Visual Studio Add-In doesn't compile `qrc` correcly
-
I use Visual Studio 2013 with Qt Visual Studio Add-In 1.2.4. I used GUI to add resource (HTML file) to form
qrcfile. My qrc file follows:<RCC> <qresource prefix="/MainWindow"> <file>default.html</file> <file>ajax-loader.gif</file> </qresource> </RCC>This file is generated by GUI, so, in ideal world, it has to work without any problems. However, when I run following code:
QFile file(":/MainWindow/default.html"); QByteArray dump = file.readAll(); qDebug() << "contents: " << dump; qDebug() << "error status: " << file.error();I receive following message:
QIODevice::read (QFile, ":\MainWindow\default.html"): device not openIs there a way to make it working?
-
As the error message suggests you need to open the file first before you can
readAllfrom it. -
Here is a classic way to open a text file in read mode:
QFile file(":/MainWindow/default.html"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { qDebug() << "error status: " << file.error(); return; } QByteArray dump = file.readAll(); qDebug() << "contents: " << dump; -
Ok, I fixed & added
openmethod call. Now I receive following error:error status: 5Documentation says that this error code means "The file could not be opened."
I put this code just to indicate broader problem: resources added from GUI doesn't work as expected. I added image and assigned it toQLabelpixmap, however, it also doesn't work. I added it also via GUI, and Qt Designer sees that image (and displays label with image correctly), but after recompilation with Visual Studio image is invisible in window. It looks like Qt Visual Studio add-in ignores this qrc file, however, it is one created automatically when I added new form, and I don't see any error messages or warnings. -
I found solution myself. After
qrcfile modification it is required to removeqrcfile from Visual Studio project and add it back. When done, Visual Studio recompilesqrcand it is possible to read resources as files.
Togeather with another known bug of Qt for Visual Studio (I am about the fact that it is required to commentQ_OBJECT, rebuild, and uncoment it back to force Qt for Visual Studio Add-In to compile correctly some changes in Visual Studio project), I can say that Qt for Visual Studio Add-In ignores many changes in source code and requires to recreate project periodically to affect changes. It makes problems for big projects with a lot of windows and resources.