我无法在qt中为可执行文件添加图标

时间:2017-07-21 14:57:34

标签: c++ qt user-interface

我似乎无法在QT中向exe文件添加图标。我已将其添加到左上角但是当我将RC_FILES = icon.ico添加到我的.pro文件时,它会在生成的资源文件中出现错误。错误说myapp_resource_res.o Error 1。这是我的.pro文件:

    #-------------------------------------------------
          #
         # Project created by QtCreator 2017-07-18T13:42:18
      #
      #-------------------------------------------------

     QT       += core gui

        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

       TARGET = MentalMath3
            TEMPLATE = app

         # The following define makes your compiler emit warnings if you use
  # any feature of Qt which as 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.0



 SOURCES += \
    main.cpp \
    mainwindow.cpp

  HEADERS += \
    mainwindow.h

  FORMS += \
  mainwindow.ui

  RC_ICONS = icon.ico

这是生成的resource.o文件:

    #include <windows.h>

      IDI_ICON1 ICON    DISCARDABLE "C:\\Users\\abhi\\Desktop\\Mental 
      Math\\MentalMath3\\icon.ico"

     VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,0,0
PRODUCTVERSION 0,0,0,0
FILEFLAGSMASK 0x3fL
    #ifdef _DEBUG
FILEFLAGS VS_FF_DEBUG
    #else
FILEFLAGS 0x0L
   #endif
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "CompanyName", "\0"
            VALUE "FileDescription", "\0"
            VALUE "FileVersion", "0.0.0.0\0"
            VALUE "LegalCopyright", "\0"
            VALUE "OriginalFilename", "MentalMath3.exe\0"
            VALUE "ProductName", "MentalMath3\0"
            VALUE "ProductVersion", "0.0.0.0\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x0409, 1200
    END
         END
     /* End of Version info */

1 个答案:

答案 0 :(得分:0)

我在开发qt应用程序时遇到了同样的问题,以解决问题。

  • 第一步:

    创建一个名为项目的资源文件,例如我的项目是Qtapp,因此资源文件内部将是“Qtapp.rc”:

#include <windows.h> IDI_ICON1 ICON DISCARDABLE "iconEXE.ico"

  • 第二步:

    返回.pro文件并添加这样的资源文件 RC_FILE = Qtapp.rc 和享受