.rcc file not found when trying to call registerSo

2019-07-24 16:49发布

问题:

I have generated a .rcc file using the following command:

rcc -binary redTheme/redTheme.qrc -o redTheme.rcc

I then put the redTheme.rcc file into the binary folder. Finally, I register the file with registerResource(const QString & rccFileName, const QString & mapRoot = QString()):

QResource::registerResource("redTheme.rcc")

The method returns false. Do I need to set a path or something similar?

Note that I'm using MSVC 2013 with CMake. According to this post, it could be a problem.

回答1:

You might need to pass an absolute path. For example:

QResource::registerResource(QCoreApplication::applicationDirPath() + "/redTheme.rcc");

One way to confirm this is to check if the following statement returns true:

QFile::exists("redTheme.rcc")