Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Resource path does not work...
I am fairly new to Qt, and I am trying to include a file using the Qt resource system.
@RESOURCES += test.qrc@
the test.qrc file reads
now, I am trying to access the file by the usual syntax,
unfortunately, this just treats the ://somepath/somefile as a literal string somehow, and does not resolve the resource path!! I am clueless why that might be happening. Can anyone suggest why?
hskoglund last edited by hskoglund
Hi, try change your test.qrc to:
<RCC> <qresource> <file>somepath/somefile</file> </qresource> </RCC>
and access it with:
P.S. Also, check that you can see your resource file in QtCreator in the Projects/Resources folder (verifying that the file path is correct.)
Thanks for your reply.
I have already tried those things, but none are working. I tried your modification also, but I got the same result. Am I missing something fundamental here?
hskoglund last edited by
Hi, I tried with your test.qrc above (I created a new simple widgets app):
first I checked that test.qrc showed up in the Qt Creator's Resources folder (underneath the Forms folder) also that I can doubleclick on somepath/somefile and that the contents appear in Qt Creator's edit window.
Then i tested with my simple untitled widgets app, inserted 2 new include lines at the top:
#include "QFile.h" #include "qDebug.h"
added these 3 lines to get the contents of somepath/somfile:
QFile file(":/somepath/somefile"); file.open(QIODevice::ReadOnly); qDebug() << file.readAll();
and sure enough the debug output shows the contents as well.
Should work for you as well, I hope!
I have found the issue. I was trying to run a script that I was loading as a resource. As I know now, that is not possible. Instead, I have to package the file, and I found a way to do that. Thanks to you of course, I was able to sort this out. When I saw that I can read the file but cannot access the path, then I realised, this is not what I wanted.