之前一直用的是qt5.9.1,正常使用,基本沒有什么問題。撰寫完一個小專案后,想要給應用程式圖示變一變。
于是請教網上的各個大神的方法,得到了基本思路。如下:
win32:RC_FILE += ico.rc
或者
RC_ICONS = ico.ico
但是無論我怎么嘗試,編譯的時候始終報錯。我在翻閱各種大神經驗的時候,注意到了有個人說可能是因為版本問題。
又于是,我果斷換了個版本直接下載目前最新的開發工具qt 5.13。下載地址:
http://download.qt.io/archive/qt/
安裝完成后,打開工程,編譯通過,果然是工具的問題。
然而換用新版本,也讓我發現了新的問題:
(1)release檔案中的exe,不能直接運行,需要windeployqt之后才可以。
(2)release編譯,程式運行,串口不能正常作業。串口收不到資料,發送也只能在剛connect之后,才可以發送一次。我打開之前用低版本編譯發布后的程式,串口正常作業。由此推斷,qt5.13對串口的支持不是很好。這樣嚴重影響了我的除錯。(不可能改一點,就windeploqt的)。
于是我決定再換一個版本,選用Qt 5.9.8版本。該版本,對于程式圖示改變,和串口功能都是可以正常支持的。
突然想到發個帖子,留給他人做參考。如果各位大佬知道問題的根本原因,希望可以告知。
uj5u.com熱心網友回復:
自己回復一下自己,緩解一下尷尬的氣氛
uj5u.com熱心網友回復:
一般開發的時候就在qt里面直接運行,到最后打包軟體的時候才用windeployqt一下找齊需要的庫檔案; 想問一下編譯報錯是因為加了RC_ICONS = ico.ico這句話嗎?如果這句有問題你的工程應該都不能正常加載了吧,我用的還是qt5.4呢,可以正常加載圖示啊uj5u.com熱心網友回復:
是的,添加這句話會報錯,去掉就可以正常編譯。換成其他版本,這個問題消失。
uj5u.com熱心網友回復:
RC_ICONSWindows only. Specifies the icons that should be included into a generated .rc file. This is only utilized if the RC_FILE and RES_FILE variable are not set. More details about the generation of .rc files can be found in the Platform Notes.
這是Qt5.12.5版本說明。RC_ICONS和RC_FILE或者RES_FILE不能同時都設定。
下邊是如何添加.rc
Adding Windows Resource Files
This section describes how to handle a Windows resource file with qmake to have it linked to an application executable (EXE) or dynamic link library (DLL). qmake can optionally auto-generate a suitably filled Windows resource file.
A linked Windows resource file may contain many elements that can be accessed by its EXE or DLL. However, the Qt resource system should be used for accessing linked-in resources in a platform-independent way. But some standard elements of the linked Windows resource file are accessed by Windows itself. For example, in Windows explorer the version tab of the file properties is filled by resource elements. In addition, the program icon of the EXE is read from these elements. So it is good practice for a Qt created Windows EXE or DLL to use both techniques at the same time: link platform-independent resources via the Qt resource system and add Windows specific resources via a Windows resource file.
Typically, a resource-definition script (.rc file) is compiled to a Windows resource file. Within the Microsoft toolchain, the RC tool generates a .res file, which can be linked with the Microsoft linker to an EXE or DLL. The MinGW toolchain uses the windres tool to generate an .o file that can be linked with the MinGW linker to an EXE or DLL.
The optional auto-generation of a suitably filled .rc file by qmake is triggered by setting at least one of the system variables VERSION and RC_ICONS. The generated .rc file is automatically compiled and linked. Elements that are added to the .rc file are defined by the system variables QMAKE_TARGET_COMPANY, QMAKE_TARGET_DESCRIPTION, QMAKE_TARGET_COPYRIGHT, QMAKE_TARGET_PRODUCT, RC_CODEPAGE, RC_ICONS, RC_LANG,and VERSION.
If these elements are not sufficient, qmake has the two system variables RC_FILE and RES_FILE that point directly to an externally created .rc or .res file. By setting one of these variables, the specified file is linked to the EXE or DLL.
Note: The generation of the .rc file by qmake is blocked, if RC_FILE or RES_FILE is set. In this case, no further changes are made to the given .rc file or the .res or .o file by qmake; the variables pertaining to .rc file generation have no effect.
uj5u.com熱心網友回復:
ico.ico放在什么地方?uj5u.com熱心網友回復:
代碼的pro檔案旁邊,不需要放到release檔案夾里uj5u.com熱心網友回復:
Qt 5.13.1版本,QSerialPort不能產生readyRead信號,這是一個BUG,Qt 5.12.5也有同樣的問題uj5u.com熱心網友回復:
原來如此uj5u.com熱心網友回復:
記得之前也有一位壇友提過 Qt5.13串口有問題,可以用第三方庫的CSerialPort
uj5u.com熱心網友回復:
已經修復了uj5u.com熱心網友回復:
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/74116.html
標籤:Qt
