简体   繁体   中英

Application icons don't show in Qt 5.0.1

I have an application I developed with Qt 4.8 (that works fine) and now I'm trying to migrate it to Qt 5. I downloaded and installed Qt Creator 2.6.2 (with Qt 5) but I have some problems with it...

The program runs and works, but it doesn't display any of the icons it has.

I have my resources file with "/" prefix and I call my resources this way, for example:

splash->setPixmap(QPixmap(":/images/xml.png"));

In my debug proyect folder I have the resources file (icons.qrc) and in that same location the folder called "images".

This is the same configuration that worked with Qt 4.8, but now I can't find a way to make the icons show...

I'm missing something????

Thanks.

You need to ensure your file is registered under the right prefix in your resource file. Folder where the file is located on your disk is not important to load resources in your c++ code.

You have to create the prefix "images" in your resource file (Add > Add prefix) then add "xml.png" as file under this prefix. If you choose to set an alias on your file (for example "xml_img"), your resource will be loadable in your code by:

splash->setPixmap(QPixmap(":/images/xml_img"));

I had the same problem, I ported from Qt 4.6.2 to Qt 5.6.2... I found out this document: http://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE According to this in Qt5, all resources must be initiated.

So, it needs to be done right in the beginning. So your "main.cpp" file should look somewhat like this:

#include "myResource.qrc.cpp"
void myFunction(){
    Q_INIT_RESOURCE(myResource);
}

This seemed to work me. But look into the document specifically to see if that works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM