[問題][QT] 如何解壓縮到自己程式的變數裡

看板C_and_CPP (C/C++)作者 (薯)時間2年前 (2021/05/08 12:52), 編輯推噓2(203)
留言5則, 3人參與, 2年前最新討論串1/1
我的開發平台是 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" 希望有人能出手相救,感謝閱讀 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.192.225.144 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1620449560.A.BCB.html

05/08 14:27, 2年前 , 1F
你預期 7zip 解壓縮檔案時,標準輸出會是什麼內容?
05/08 14:27, 1F

05/08 14:30, 2年前 , 2F
是不是有漏加參數
05/08 14:30, 2F

05/08 14:49, 2年前 , 3F

05/08 14:49, 2年前 , 4F
zip-into-qbytearray
05/08 14:49, 4F

05/10 12:09, 2年前 , 5F
readLine()讀取的是stdout 你要叫7z解到stdout
05/10 12:09, 5F
文章代碼(AID): #1WbXaOlB (C_and_CPP)
文章代碼(AID): #1WbXaOlB (C_and_CPP)