Ressource File Url not opened by QFile
-
wrote on 29 May 2018, 03:37 last edited by
Hello Everyone,
I have attached herewith a simple project using a simple resource file that cannot be opened by QFile. I have just built the latest version of QT5.11 from source using Git and Qt Creator 4.7.82 from source (latest git version check out). For both, I used the same Visual Studio Enterprise 2017 version 15.7.2.
Can anyone please tell me what could be wrong?
Thanks in Advance.
[0_1527563530808_TestQFile.rar](Uploading 100%) -
wrote on 29 May 2018, 03:55 last edited by
I dont understand you cleary. You have a TestQFile.rar in your Resource and you just want to access it with the Url in a QFile? The Problem is maybe that everything in the Resource File, that is compiled into your Executable, is ReadOnly.
-
Hi,
What error do you get ?
What code are you using ?
By the way, upload of compressed archived are not enabled.
-
wrote on 29 May 2018, 17:51 last edited by
Hello and thanks for the answers.
I have a simple .txt file and I try to access it with QFile::open(). The following if always fails, no matter which projects[0_1527616248419_textfinder.cpp](Uploading 100%) :QFile inputFile("qrc:/Resources/input.txt"); if (!inputFile.open(QIODevice::ReadOnly)){ qDebug() << "could not open " << inputFile.fileName() <<"\n"; if (QFile::exists("qrc:/Resources/input.txt")){ qDebug() << "could not find existing file " << inputFile.fileName() <<"\n"; } return; }
The console gives me:
Starting E:\Qt\Tutorials\QtCreator\build-TextFinder-x64-Debug\debug\TextFinder... could not open "qrc:/Resources/input.txt" E:/Qt/Tutorials/QtCreator/build-TextFinder-x64-Debug/debug/TextFinder exited with code 0
[0_1527616275931_textfinder.cpp](Uploading 100%)
[0_1527616287093_textfinder.qrc](Uploading 100%) -
You should use
:/
to access your resources like shown here.Can you post your
.qrc
file content ? -
wrote on 2 Jun 2018, 16:26 last edited by Chrysmac 0 6 Feb 2018, 16:27
Sorry for my absence. I have tried almost every combination of /,//,///,\ and so on.
My Qrc file content is<RCC> <qresource prefix="/" lang="C++"> <file>Resources/input.txt</file> </qresource> </RCC>
-
Lifetime Qt Championwrote on 2 Jun 2018, 16:43 last edited by mrjj 6 Feb 2018, 16:49
Hi
And you are using the plugin and are sure the files are actually compiled into the code ?
http://doc.qt.io/archives/vs-addin/vs-addin-managing-resources.htmlI would do something like
QDirIterator it(":", QDirIterator::Subdirectories); while (it.hasNext()) { qDebug() << it.next(); }
to see what you got.
1/7