本文主要描述如何在Qt Creator中创建资源文件,并的打入导入图标文件。
查看图标资源文件时,可以在项目的工程文件上鼠标单击右键-Open With-资源编辑器,效果如下图所示:
在项目的工程文件上鼠标单击右键-Open With-普通文本编辑器,效果如下图所示:
如果需要导入已经存在的资源文件和图标文件,如saribbonresouce.qrc是已经存在的资源文件,icon是已经存在的图标文件,见下图所示,
如果需要导入已经存在的资源文件和图标文件,则只需要在项目的项目文件*.pro中最后添加如下蓝色标注的语句:
#-------------------------------------------------
#
# Project created by QtCreator --20T22::
#
#-------------------------------------------------QT += core guigreaterThan(QT_MAJOR_VERSION, ): QT += widgetsTARGET = MyRibbonWindow
TEMPLATE = app# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.#配置本应用程序编译后的输出路径
CONFIG(debug, debug|release){
DESTDIR = $$PWD/../bin_qt$$[QT_VERSION]_debug
}else {
DESTDIR = $$PWD/../bin_qt$$[QT_VERSION]_release
}SOURCES += \
main.cpp \
mainwindow.cppHEADERS += \
mainwindow.hFORMS += \
mainwindow.uiRESOURCES += \
saribbonresouce.qrc \#此处的$$PWD代表D:\MyProject\MyRibbonDemo\MyRibbonWindow\MyRibbonWindow.pro文件所在的目录
include($$PWD/../SARibbonBar.pri)
之后,按下“Crtl+S”保存,Qt Creator就会自动扫描和导入图标资源。如果未自动加载,可将Qt Creator关闭后再重启,一般就可加载成功。