Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open resource file

Tags:

qt

qt5

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?

like image 212
user2277695 Avatar asked Apr 13 '13 14:04

user2277695


People also ask

How do you open a resource?

From the Windows Task Manager Press the Ctrl + Alt + Del keys at the same time and select Start Task Manager on the screen that appears. In the Task Manager, click the Performance tab, then click the Resource Monitor button or Open Resource Monitor link, depending on your version of Windows.

How do I open a resource extension?

If you cannot open your RESOURCE file correctly, try to right-click or long-press the file. Then click "Open with" and choose an application. You can also display a RESOURCE file directly in the browser: Just drag the file onto this browser window and drop it.

What is a resource file?

Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more. You should always externalize app resources such as images and strings from your code, so that you can maintain them independently.


2 Answers

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

like image 155
Milania Avatar answered Oct 05 '22 10:10

Milania


Does the URL notation

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

work for you?

like image 20
Burkhard Avatar answered Oct 05 '22 11:10

Burkhard