QT預編譯加快速度(轉)
阿新 • • 發佈:2022-05-17
原文:https://beondxin.blog.csdn.net/article/details/98480663
臨時有需求寫些小的任務,比如檔案流操作,圖片加水印等完成快速部署,或者比較大的專案,編譯速度過慢,這時就需要設定預編譯。建完新工程實現快速部署和編譯。
qt使用預編譯只需要在.pro或者任意一個.pri裡新增兩行就可以了
CONFIG += precompile_header
PRECOMPILED_HEADER=$$PWD/stable.h
我分享下我常用的pro模板和預編譯檔案,便於快速部署
QT += core gui network sql serialport widgets #qt引用模組 核心功能、介面、網路、串列埠 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets #過程檔案存放位置 MOC_DIR = temp/moc #指定moc命令將含Q_OBJECT的標頭檔案轉換成標準.h檔案的存放目錄 RCC_DIR = temp/rcc #指定rcc命令將.qrc檔案轉換成qrc_*.h檔案的存放目錄 UI_DIR = temp/ui #指定rcc命令將.qrc檔案轉換成qrc_*.h檔案的存放目錄 OBJECTS_DIR = temp/obj #指定目標檔案(obj)的存放目錄 #指定生成的應用程式放置的目錄 DESTDIR = bin #指定生成的應用程式名和圖示 TARGET = YX_case RC_ICONS= myico.ico #工程中包含的資原始檔 DEFINES += QT_DEPRECATED_WARNINGS #定義編譯選項,在.h檔案中就可以使用:#ifdefine xx_xx_xxx #指定編譯器選項和專案配置 CONFIG += warn_on #告訴qmake要把編譯器設定為輸出警告資訊的。 CONFIG += precompile_header #可以在專案中使用預編譯標頭檔案的支援。 #預編譯 PRECOMPILED_HEADER=$$PWD/stable.h
//stable.h #if defined __cplusplus #include <iostream> #include <vector> #include <QApplication> #include <QtCore> #include <QtGui> #include <QTimer> #include <QtNetwork> #include <QTextCodec> #include <QThread> #include <windows.h> #include <QtSql> #if (QT_VERSION > QT_VERSION_CHECK(5,0,0)) #include <QtWidgets> #endif #define BOOL_VERIFY(emStatus_bool,switch_bool) \ if (emStatus_bool == true){return true;}\ else{return false;} #define NULL_VERIFY(emStatus_null,switch_null) \ if (emStatus_null != NULL){return true;}\ else{return false;} #define AppPath qApp->applicationDirPath() #define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz")) #define TIME qPrintable(QTime::currentTime().toString("HHmmss")) #define QDATE qPrintable(QDate::currentDate().toString("yyyy-MM-dd")) #define QTIME qPrintable(QTime::currentTime().toString("HH-mm-ss-zzz")) #define DATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss")) #define STRDATETIME qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss")) #define STRDATETIMEMS qPrintable(QDateTime::currentDateTime().toString("yyyy-MM-dd-HH-mm-ss-zzz")) #pragma execution_character_set("utf-8") #endif