Qt / C ++:程序运行时图标不显示 [英] Qt/C++: Icons not showing up when program is run

查看:517
本文介绍了Qt / C ++:程序运行时图标不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Qt Designer的MainWindow中为我的 QToolBar 添加了 QAction (使用Qt Creator IDE并给予Action一个图标(由选择文件完成并选择与我的项目和源代码位于同一目录中的.png)。图标在Qt Designer的工具栏中显示正常,但在项目运行时不显示。在Windows上选择标题栏图标时遇到了类似的麻烦。我以前从未在Qt中使用过图形,我需要做些什么特别的事情吗?

I've added a QAction to my QToolBar in my MainWindow in Qt Designer (using the Qt Creator IDE) and given that Action an icon (done by "Choose File" and selecting my .png located in the same directory as my project and source code). The icon shows up fine in the toolbar in Qt Designer, but does not show when the project is running. I've had similar trouble when choosing the title bar icon on windows. I've never used graphics in Qt before, is there something special I need to do?

屏幕截图:

Screenshot:

推荐答案

您是否制作了QRC文件(即Qt相当于资源文件?)
如果没有,那可以解释一下你是什么我看到了。图标将显示在创建者中,但不会显示在最终编译的可执行文件中。看看这个:

Did you make a QRC file (that is, Qt's equivalent of a resource file?) If not, that would explain what you're seeing. The icons will show up in the creator, but not in the final compiled executable. Have a look at this:

http://doc.qt.io/qt-5/resources.html

这篇关于Qt / C ++:程序运行时图标不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆