Aidin.T
Aidin.T

Reputation: 771

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?

Upvotes: 3

Views: 1908

Answers (1)

cmannett85
cmannett85

Reputation: 22366

It should be:

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

(Note the slash)

Upvotes: 4

Related Questions