Resource problem with cmake
-
wrote on 11 Oct 2014, 13:29 last edited by
Hi everyone,
I am building a desktop app with Qt 5.3.1 and cmake 3, and have some troubles with the resources. I have a .qss file which works fine when loading directly from main.cpp, but when it comes to using resources, it does not work.
I have one .qrc file in the same folder as the main.cpp, and added the .qss file in the qrc , my code is the following:
@<RCC>
<qresource prefix="/">
<file>Resources/ScStyleSheet.qss</file>
</qresource>
</RCC>@My code in main.cpp :
@ QFile File(":/ScStyleSheet.qss");
File.open(QIODevice::ReadOnly | QIODevice::Text);
QString StyleSheet = QLatin1String(File.readAll());a.setStyleSheet(StyleSheet);@
When I want to use this resource, I get an error: "QIODevice::read: device not open"
In my cmakelists.txt, the relevant section is:
@set (project_RESOURCES ScRes.qrc )
QT5_WRAP_CPP (project_HEADERS_MOC ${project_HEADERS})
QT5_WRAP_UI (project_FORMS_HEADERS ${project_FORMS})
QT5_ADD_RESOURCES (project_RESOURCES_RCC ${project_RESOURCES})set_source_files_properties(${project_RESOURCES_RCC} PROPERTIES GENERATED ON)
ADD_EXECUTABLE (Scanopus ${project_SOURCES} ${project_FORMS_HEADERS} ${project_HEADERS_MOC} ${project_RESOURCES})@
The cmakelists.txt is also in the same folder with the .qrc and the main.cpp files.
Does anyone have any suggestions on why my resource does not load correctly?
Thank you in advance,
András -
Hi, welcome to devnet.
You should check your return codes. You won't be able to read the file if QFile::open returns false.
Anyway, with that resource file structure you should adjust your path like this:
@QFile File(":/Resources/ScStyleSheet.qss");@ -
wrote on 13 Oct 2014, 13:32 last edited by
Hi Chris,
Thanks for your response. Actually, the other way doesn't work either. I get a "device not open" message. I have the qrc_ScRes.cpp generated but I cannot open the .qss from the resource. File.errorString() returns "Unknown error", and File.error() returns OpenError (0n5). Does this say something to you?Thanks
András
1/3