8

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?

user2277695
  • 83
  • 1
  • 1
  • 3

3 Answers3

11

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

Milania
  • 565
  • 7
  • 15
9

Does the URL notation

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

work for you?

Burkhard
  • 169
  • 1
  • 3
  • 1
    Turns out the project was corrupted. – user2277695 Apr 13 '13 at 16:34
  • I just tried out your code and it worked fine for me. Of course, I used `QFile test(":/needle.png");`. I think your code - as posted here - is OK. Where are your qrc and png files located? What's the content of your pro file? – Burkhard Apr 13 '13 at 16:45
  • Saw your second comment too late. So, all is fine ;) – Burkhard Apr 13 '13 at 16:46
0

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

Charles O
  • 1
  • 1