贊助廠商

娛樂城推薦

首頁

電腦與網際網路/其他:電腦列表

C/C++-[QT

我的開發平台是 win7工具是QT Creator版本是Qt Core 5.15.2我想使用QProcess呼叫7z.exe幫我解壓縮但不是單純地解壓縮在硬碟裡面而是把檔案解壓縮後的meta data導流到我的程式變數裡讓我可以做後續的動作原本我是使用QT內建的 QByteArray QZipReader::fileData(QString filePath)現在我想用7z取代QZipReader。但目前卡在不知道該怎麼取得7z解壓縮後的fileData雖然我也可以讓7z解壓縮到硬碟之後openFile使用QImage::loadFromData(QByteArray);然後再把那個暫時檔案給刪掉。但如果可以的話我希望可以直接解壓縮到我的程式變數裡但我測試了一個早上都還是失敗....不知道該往哪裡去找答案...以下是我的程式碼首先得到壓縮檔內的檔案名稱沒有問題成功利用7z取得某一壓縮檔內所有的檔案名稱(路徑) QProcess proccess{nullptr}; QString exe = "7z.exe"; QStringList args; args << "l" << "-slt" << mPath; proccess.start(exe, args); proccess.waitForFinished(); QString prefix{"Path = "}; while (!proccess.atEnd()){ QString line{QString::fromLocal8Bit(proccess.readLine())}; if (!line.startsWith(prefix)) continue; line.chop(2); if ( !line.endsWith(".jpg", Qt::CaseInsensitive) && !line.endsWith(".png", Qt::CaseInsensitive) && !line.endsWith(".gif", Qt::CaseInsensitive) && !line.endsWith(".bmp", Qt::CaseInsensitive) ) continue; mInfoList.enqueue(line.mid(prefix.length())); }但是在取得fileData這一塊我卻失敗了指令的部分在command line是通過的,可以解壓單個檔案到該目錄下QByteArray GalleryReader::getZipFileData(QString filePath){ QProcess process{nullptr}; QString exe = "7z.exe"; QStringList args; args << "x" << mPath << filePath; qDebug() << "" << args ; process.start(exe, args); process.waitForFinished(); return process.readAllStandardOutput();}然而QProcess不論使用哪個read 的函式,都沒有讀到東西readLine 也只會得到"\r\n"希望有人能出手相救,感謝閱讀--
  • 發問日期:2021-06-13 17:10:08

友站連結