string轉QBytearray

最近在程序中遇到要把圖片的二進制string存成圖片到本地,其實就是寫文件app

                                        structCameraInfo tmpCameraInfo;
                                        string strData = tmpCalibrateReq.images(i).data();
                                        string strCameraName = tmpCalibrateReq.images(i).camera_name();
                                        QFile file;
                                        QString strImgPath = qApp->applicationDirPath() + "/" + QString::fromStdString(strCameraName) + ".jpg";
                                        file.setFileName(strImgPath);
                                        if(file.open(QIODevice::WriteOnly))
                                        {
                                            //QByteArray tmpByteArray = QString::fromStdString(strData).toLatin1();這種寫法是錯誤的
                           QByteArray tmpByteArray(strData.c_str(), strData.length());//這纔是正確的 file.write(tmpByteArray); file.close(); }

https://cloud.tencent.com/developer/ask/32018spa

這個連接解釋的很清楚code

相關文章
相關標籤/搜索