預設的專業檔案

qmake 是一個構建自動化工具,隨 Qt 框架一起提供。它與 CMakeGNU Autotools 等工具的作用相似,但它專門用於 Qt 。因此,它與 Qt 生態系統很好地整合,尤其是 Qt Creator IDE。

如果你啟動 Qt Creator 並選擇 File -> New File or Project -> Application -> Qt Widgets 應用程式, Qt Creator 將為你生成一個專案框架以及一個 pro 檔案。pro 檔案由 qmake 處理以生成檔案,檔案又由底層構建系統處理(例如 GNU Makenmake )。

如果你將專案命名為 myapp,則會出現“myapp.pro”檔案。以下是這樣的預設檔案的外觀,以及用於描述每個 qmake 變數的註釋。

# Tells build system that project uses Qt Core and Qt GUI modules.
QT       += core gui

# Prior to Qt 5 widgets were part of Qt GUI module. In Qt 5 we need to add Qt Widgets module.
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

# Specifies name of the binary.
TARGET = myapp

# Denotes that project is an application.
TEMPLATE = app

# List of source files (note: Qt Creator will take care about this list, you don't need to update is manually).
SOURCES += main.cpp\
        mainwindow.cpp

# List of header files (note: Qt Creator will take care about this list).
HEADERS  += mainwindow.h

# List of "ui" files for a tool called Qt Designer, which is embedded into Qt Creator in newer versions of IDE (note: Qt Creator will take care about this list).
FORMS    += mainwindow.ui