
正文
C/C++ -- Gui编程 -- Qt库的使用 -- 使用.ui文件
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
1.创建Qt空工程
2.添加Qt设计师界面,无按钮对话框helloqt.ui
3.编辑界面,添加部件,修改对话框对象名为HelloQt
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>HelloQt</class> <widget class="QDialog" name="HelloQt"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle"> <string>Dialog</string> </property> <widget class="QLabel" name="lbl"> <property name="geometry"> <rect> <x>170</x> <y>140</y> <width>54</width> <height>12</height> </rect> </property> <property name="text"> <string>哈喽Qt</string> </property> </widget> </widget> <resources/> <connections/> </ui>
4.构建生成Ui头文件''ui_helloqt.h''
5.添加main.cpp,使用构建生成的ui头文件
#include "ui_helloqt.h" int main(int argc, char * argv[]) { QApplication app(argc, argv); QDialog dlg; Ui::HelloQt ui; ui.setupUi(&dlg); dlg.show(); return app.exec(); }
备注:
ui对象也可以用Ui_HelloQt实例化,因为Ui::HelloQt完全没有更改地继承自Ui_HelloQt
namespace Ui { class HelloQt: public Ui_HelloQt {}; } //
命令行下编译.ui文件
uic -o 目标文件.h 源文件.ui
比如 uic -o ui_helloqt.h helloqt.ui







