2

I have encountered a strange issue where QFile.open is unable to open a file which is added in the qrc resource file. My qrc file looks like this

enter image description here

I'm using following code to read the file theme_normal.qss

QFile file(":/styles/theme_normal.qss");

if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
    QString style(file.readAll());
    file.close();
}
else
{
    QMessageBox::critical(nullptr, "Error", "Error loading style file: " +  file.errorString());
}

I'm getting following error: No such file or directory

Same code (as it is) works fine in Qt 5.7.0. I'm facing above issue with Qt 5.9.2. What could be the reason?

My example project: https://github.com/warunanc/QtFileFromResources

warunanc
  • 2,221
  • 1
  • 23
  • 40

2 Answers2

0

In my similar case the problem was solved after removing all Qt DLL files from appication dir (system: Windows 10) and copy new DLL files.

I found that in 5.9 there is no more Qt5CLucened.dll for example. Possible problem was in obsolete Qt5CLucened.dll file

0

In case anyone have similar case.

My environment : ubuntu 16.04 LTS, Qt 5.9.4.

I have tried:

  1. reboot system.

  2. restart Qt creator

  3. clean project, build qmake and rebuild project

  4. changed qrc prefix

  5. remove qrc's target file and add it again

There are no help.

Finally, I remove the qrc and add a new qrc with same name and same file, and remove old qrc_xxx.cpp and qrc_xxx.o in build folder, it also doesn't help.

But, I remove the qrc and add a new qrc with different name, such that, old qrc named res.qrc and new qrc named res1.qrc, then build qmake and build project, it works fine!!!

I don't know why, maybe some old caches? It takes me long times..):

EDIT: I found the reason is that if you use SUBDIRS in .pro and have two project have same name qrc, you will get this trouble.

Shun
  • 147
  • 11