C/C++-[QT

匿 匿名 607 次瀏覽 0 個回答

我的開發平台是 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"

希望有人能出手相救,感謝閱讀

--

我要回答

0 個回答

還沒有人回答,你知道答案嗎?

我要回答

登入會員後即可回答問題。

免費註冊