简体   繁体   English

Qt 5.0.1中不显示应用程序图标

[英]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... 我有一个使用Qt 4.8开发的应用程序(工作正常),现在我正尝试将其迁移到Qt5。我下载并安装了Qt Creator 2.6.2(使用Qt 5),但是我有一些问题。 。

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". 在我的debug proyect文件夹中,有资源文件(icons.qrc),在同一位置,有一个名为“ 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... 这与使用Qt 4.8的配置相同,但是现在我找不到一种方法来显示图标...

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. 该文件位于磁盘上的文件夹对于在c ++代码中加载资源并不重要。

You have to create the prefix "images" in your resource file (Add > Add prefix) then add "xml.png" as file under this prefix. 您必须在资源文件(添加>添加前缀)中创建前缀“图像”,然后在该前缀下将“ xml.png”添加为文件。 If you choose to set an alias on your file (for example "xml_img"), your resource will be loadable in your code by: 如果选择在文件上设置别名(例如“ xml_img”),则可以通过以下方式将资源加载到代码中:

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. 我遇到了同样的问题,我从Qt 4.6.2移植到了Qt 5.6.2 ...我发现了这个文档: http : //doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE Qt5,必须启动所有资源。

So, it needs to be done right in the beginning. 因此,它需要在一开始就完成。 So your "main.cpp" file should look somewhat like this: 因此,您的“ main.cpp”文件应如下所示:

#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. 但是,请仔细研究该文档,看看是否适合您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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