user2277695
user2277695

Reputation: 83

Cannot open resource file

Here is my code:

QFile test("://needle.png"); // also tried :/needle.png :\needle.png :\\needle.png

if(test.open(QFile::ReadOnly)) {
    qDebug() << "yay";
} else {
    qDebug() << "fail";
}

I have this in my project file:

RESOURCES += Resources.qrc

Here is my QRC file:

<RCC>
    <qresource prefix="/">
        <file>needle.png</file>
    </qresource>
</RCC>

I keep getting fail as output. Any ideas?

Upvotes: 8

Views: 12581

Answers (3)

Charles O
Charles O

Reputation: 1

I removed the project.user.pro file, reopened QT. And it chose the kit and rebuilt. Working now.

Upvotes: 0

Milania
Milania

Reputation: 615

I had exactly the same problem. Running qmake again finally worked (build -> run qmake).

Upvotes: 11

Burkhard
Burkhard

Reputation: 169

Does the URL notation

QFile test("qrc:///needle.png");

work for you?

Upvotes: 9

Related Questions