- Qt編程快速入門
- 鮑忠貴
- 517字
- 2021-03-19 17:41:44
1.3 了解Qt生成的工程文件
Qt生成的工程文件包括工程文件、樣式文件、頭文件和源文件,在Qt Creator集成環境編輯模式中可以分類看到,雙擊相應的文件,就會在編輯窗口中打開,如圖1-11所示。這些文件存放在QT\Ch1目錄中。

圖1-11 編輯窗口快捷面板
1.工程文件:*.pro
工程文件定義了Qt用的類庫、目標程序的文件名,采用模板、C++源文件、C++頭文件和樣式文件,如下所示:
#------------------------------------------------- # #Project created by QtCreator 2013-11-27T15:34:33 # #------------------------------------------------- QT +=core gui TARGET=Ch1 TEMPLATE=app SOURCES+=main.cpp\ mainwindow.cpp HEADERS +=mainwindow.h FORMS +=mainwindow.ui
2.樣式文件: *.ui
樣式文件定義了人機交互界面,在設計模式下是所見即所得的窗口和控件,在編輯模式下是XML定義文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>MainWindow</class> <widget class="QMainWindow" name="MainWindow"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralWidget"/> <widget class="QMenuBar" name="menuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>17</height> </rect> </property> </widget> <widget class="QToolBar" name="mainToolBar"> <attribute name="toolBarArea"> <enum>TopToolBarArea</enum> </attribute> <attribute name="toolBarBreak"> <bool>false</bool> </attribute> </widget> <widget class="QStatusBar" name="statusBar"/> </widget> <layoutdefault spacing="6" margin="11"/> <resources/> <connections/> </ui>
Qt編譯器在編譯樣式文件時,自動將XML資源文件編譯成C++頭文件ui_mainwindow.h。該文件創建了主窗口界面類Ui_MainWindow,封裝了樣式中的窗口和控件。該文件在QT\Ch1-build-desktop目錄中。了解該文件可以更好地理解Qt界面的實現過程。
/******************************************************************************** ** Form generated from reading UI file 'mainwindow.ui' ** ** Created: Wed Nov 27 16:20:21 2013 ** by: Qt User Interface Compiler version 4.7.0 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef UI_MAINWINDOW_H #define UI_MAINWINDOW_H #include<QtCore/QVariant> #include<QtGui/QAction> #include<QtGui/QApplication> #include<QtGui/QButtonGroup> #include<QtGui/QHeaderView> #include<QtGui/QMainWindow> #include<QtGui/QMenuBar> #include<QtGui/QStatusBar> #include<QtGui/QToolBar> #include<QtGui/QWidget> QT_BEGIN_NAMESPACE class Ui_MainWindow { public: QMenuBar *menuBar; QToolBar *mainToolBar; QWidget *centralWidget; QStatusBar *statusBar; void setupUi(QMainWindow *MainWindow) { if (MainWindow->objectName().isEmpty()) MainWindow->setObjectName(QString::fromUtf8("MainWindow")); MainWindow->resize(400, 300); menuBar=new QMenuBar(MainWindow); menuBar->setObjectName(QString::fromUtf8("menuBar")); MainWindow->setMenuBar(menuBar); mainToolBar=new QToolBar(MainWindow); mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); MainWindow->addToolBar(mainToolBar); centralWidget=new QWidget(MainWindow); centralWidget->setObjectName(QString::fromUtf8("centralWidget")); MainWindow->setCentralWidget(centralWidget); statusBar=new QStatusBar(MainWindow); statusBar->setObjectName(QString::fromUtf8("statusBar")); MainWindow->setStatusBar(statusBar); retranslateUi(MainWindow); QMetaObject::connectSlotsByName(MainWindow); } // setupUi void retranslateUi(QMainWindow *MainWindow) { MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8)); } // retranslateUi }; namespace Ui { class MainWindow: public Ui_MainWindow {}; } // namespace Ui QT_END_NAMESPACE #endif // UI_MAINWINDOW_H
3. 頭文件: *.h
頭文件列出本工程包含的用戶頭文件。
4. 源文件: *.cpp
源文件列出本工程包含的用戶C++源文件。
推薦閱讀
- Extending Jenkins
- Ray分布式機器學習:利用Ray進行大模型的數據處理、訓練、推理和部署
- Python數據可視化之Matplotlib與Pyecharts實戰
- PHP+MySQL網站開發項目式教程
- ASP.NET Core 2 Fundamentals
- Visual Basic程序設計
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- ElasticSearch Cookbook(Second Edition)
- 大學計算機基礎實驗指導
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- 計算機應用基礎(第二版)
- Visual Basic語言程序設計上機指導與練習(第3版)
- Python Penetration Testing Essentials
- Tkinter GUI Application Development Blueprints
- Python High Performance(Second Edition)