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

C/C++ -- Gui编程 -- Qt库的使用 -- 使用.ui文件的更多相关文章

  1. Python -- Gui编程 -- Qt库的使用 -- 配置资源文件

    1.源文件(qtRes.py) import sys from PyQt4 import QtCore, QtGui, uic class MyDialog(QtGui.QDialog): def _ ...

  2. C/C++ -- Gui编程 -- Qt库的使用 -- 理解主窗体构造函数

    MyWidget做父窗体 MyWidget的构造函数中可以手动添加组件 Ui::MyWidget存放子部件 Ui::MyWidget执行setupUi()函数为子部件开辟空间,指定父窗体 MyWidg ...

  3. C/C++ -- Gui编程 -- Qt库的使用 -- 使用自定义类

    1.新建空Qt工程 2.新建C++类HelloQt 3.新建ui文件,添加部件,重命名主窗体(对话框)类名HelloQt,构建生成ui头文件 4.修改头文件helloqt.h #ifndef HELL ...

  4. C/C++ -- Gui编程 -- Qt库的使用 -- 标准对话框

    -----mywidget.cpp----- #include "mywidget.h" #include "ui_mywidget.h" #include & ...

  5. C/C++ -- Gui编程 -- Qt库的使用 -- 信号与槽 -- 欢迎界面

    程序运行先显示一个对话框,确定进入主程序 1.新建Qt工程,类MyWidget,基类QWidget 2.新建设计师界面类MyDialog,基类QDialog 3.-----main.cpp----- ...

  6. C/C++ -- Gui编程 -- Qt库的使用 -- 信号与槽的关联

    Qt信号与槽的三种关联方法:1.设计界面关联,编辑信号/槽,自动关联 2.手动关联(1).头文件中定义槽 -----mywidget.h----- #ifndef MYWIDGET_H #define ...

  7. C/C++ -- Gui编程 -- Qt库的使用 -- Qt5总结

    主要变化: 1.与Qt4相比,Qt5可以直接显示中文不需要手工转码2.Qt5模块发生变化,大部分组件并入widgets模块 注意事项:工程文件加一句greaterThan(QT_MAJOR_VERSI ...

  8. C/C++ -- Gui编程 -- Qt库的使用 -- Qt5试用

    1.头文件<QtGui>变成了<QtWidgets> 相应<QtGui/***>变成了<QtWidgets/***> 2.QTextCodec::set ...

  9. C/C++ -- Gui编程 -- Qt库的使用 -- 使用小写qDebug调试程序

    qDebug作为printf不需要头文件 qDebug()作为cout要使用头文件<QDebug> -----debug.cpp----- -----debug.cpp----- #inc ...

随机推荐

  1. APUE(5)---标准I/O库 (3)

    十.定位流 #include <stdio.h> long ftell(FILE *fp); //若成功,返回当前文件位置指示:若出错,返回-1L int fseek(FILE *fp, ...

  2. 绩效沟通的best原则

    绩效沟通-BEST原则 BEST原则指在进行绩效/IDP面谈的时候按照以下步骤进行: 案例:小赵经常在制作标书时候犯错误 Behavior description 描述行为 小赵,8月6日,你制作的标 ...

  3. Python学习-39.Python中的生成器

    先回顾列表解释 lista = range(10) listb = [elem * elem for elem in lista] 那么listb就将会是0至9的二次方. 现在有这么一个需求,需要存储 ...

  4. Java Spring 后端项目搭建

    参考了几位同行的Blogs和StackOverflow上的许多问答,搭建了此后端项目,替换原来的node.js后端,和前一篇中搭建的Vue Web App项目配合使用,后端准备只提供服务,不包含后端装 ...

  5. c#中取整方式

    主要用到 System 命名空间下的一个数据类 Math ,调用他的方法 一共有三种方式: 第一种 Math.Round:根据四舍五入取整 第二种 Math.Ceiling:向上取整,有小数,整数加1 ...

  6. django 实现全局支持跨域请求

    Django 实现允许跨域请求 1.安装django-cors-headers pip install django-cors-headers 2.配置settings.py文件 INSTALLED_ ...

  7. sql语句_2

    数据表如下 一个user_id对应多个user_name,现在要求是:如果某个用户对应的user_name中存在一个a,打印user_id,a出来:如果不存在,打印user_id,0.打印时候user ...

  8. 编写 ES6 的 7 个实用技巧

    无脑翻译走一波~ Hack #1 - 变量交换 使用数组解构交换变量的值 let a = 'world', b = 'hello' [a, b] = [b, a] console.log(a) // ...

  9. 本地数据库导入线上服务器的mongodb中

    更改默认端口 sudo vi /etc/mongod.conf 进入conf文件,修改port值为19999保存并退出. 重启mongodb sudo service mongod restart 进 ...

  10. 【wireshark】插件开发(四):Lua插件Post-dissector和Listener

    1. Post-dissector post-dissector和dissector不同,它会在所有dissectors都执行过后再被执行,这也就post前缀的由来.post-dissector的构建 ...