c++qtresourcesresource-file

How to access files specified in a .qrc file from the c++ code?


I created a .qrc file in Qt 5.0.1:

<RCC>
<qresource>
    <file>105.ico</file>
</qresource>
</RCC>

and I edited my .pro file:

RESOURCES += \
Icons.qrc

when I use the code below in my class constructor icon doesn't appear

 this->setWindowIcon(QIcon(":105.ico"));

but when I give a local file address instead of ":105.ico" icon shows up. what is the problem?


Solution

  • It should be:

    this->setWindowIcon(QIcon(":/105.ico"));
    

    (Note the slash)