【1】.pro

 QT       += core gui

 greaterThan(QT_MAJOR_VERSION, ): QT += widgets

 TARGET = TestDialog
TEMPLATE = app # The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0. SOURCES += main.cpp\
dialog.cpp HEADERS += dialog.h FORMS += dialog.ui

【2】.h

 #ifndef DIALOG_H
#define DIALOG_H #include <QDebug>
#include <QDialog>
#include <QPushButton>
#include <QHBoxLayout> namespace Ui
{
class Dialog;
} class MyDialog : public QDialog
{
public:
MyDialog(QWidget *parent = Q_NULLPTR);
~MyDialog(); private:
void init(); private:
QPushButton* m_p1;
QPushButton* m_p2; }; class Dialog : public QDialog
{
Q_OBJECT public:
explicit Dialog(QWidget *parent = );
~Dialog(); private slots:
void onPushButton(); private:
Ui::Dialog *ui;
MyDialog *m_pDialog;
}; #endif // DIALOG_H

【3】.cpp

 #include "dialog.h"
#include "ui_dialog.h" MyDialog::MyDialog(QWidget *parent) : QDialog(parent)
{
init();
} MyDialog::~MyDialog()
{ } void MyDialog::init()
{
m_p1 = new QPushButton(this);
m_p1->setText(QString("OK"));
m_p2 = new QPushButton(this);
m_p2->setText(QString("Cancel"));
connect(m_p1, &QPushButton::clicked, this, &MyDialog::accept);
connect(m_p2, &QPushButton::clicked, this, &MyDialog::reject);
QHBoxLayout* pHLayout = new QHBoxLayout(this);
pHLayout->addWidget(m_p1);
pHLayout->addWidget(m_p2);
setLayout(pHLayout);
} Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
m_pDialog = new MyDialog();
connect(ui->pushButton, &QPushButton::clicked, this, &Dialog::onPushButton);
} Dialog::~Dialog()
{
delete ui;
if (m_pDialog != Q_NULLPTR)
{
delete m_pDialog;
m_pDialog = Q_NULLPTR;
}
} void Dialog::onPushButton()
{
int nRet = m_pDialog->exec();
if (nRet == QDialog::Accepted)
{
qDebug() << "Click OK Button";
qApp->exit();
}
else if (nRet == QDialog::Rejected)
{
qDebug() << "Click Cancel Button";
return;
}
}

【4】main

 #include "dialog.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog w;
w.show(); return a.exec();
}

【5】验证一个问题

Good Good Study, Day Day Up.

顺序 选择 循环 总结

QDialog 使用Demo的更多相关文章

  1. QT 随笔目录

    [1]基础部分 <信号和槽机制> <信号与槽知识点> <QString 与 string转换> <QT 继承QWidget && 继承QDia ...

  2. qt5之设置无边窗口移动

    Note qt version: 5.12 qt creator: 4.13 本文将介绍 设置无边窗口和设置窗口的移动 你要知道: QDialog 和 QMainWindow都是 QWidget的派生 ...

  3. QT 入门 -QApplication QPushButton QDialog Ui类型的手工使用

    QT 1.工具 assistant  帮助文档 qtconfig  QT配置工具 qmake     QT的make与项目文件智能创建工具 uic          UI界面的设计文件的编译工具 mo ...

  4. Qt Creator简单计算器的Demo

    小编在期末数据结构课设中遇到要做可视化界面的问题,特意去学习了一下Qt的用法,今天就来给大家分享一下. 我用的是Qt5.80,当然这只是一个简易的计算器Demo,,请大家勿喷. 首先我创建了一个Qt ...

  5. QDialog对话框

    QDialog对话框,用来实现那些只是暂时存在的用户界面,是独立的窗口,但通常也有父窗口对话框有模态和非模态两种,,非模态对话框的行为和使用方法都类似于普通的窗口,模态对话框则有所不同,当模态对话框显 ...

  6. 通过一个demo了解Redux

    TodoList小demo 效果展示 项目地址 (单向)数据流 数据流是我们的行为与响应的抽象:使用数据流能帮我们明确了行为对应的响应,这和react的状态可预测的思想是不谋而合的. 常见的数据流框架 ...

  7. 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo

    有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...

  8. 在线浏览PDF之PDF.JS (附demo)

    平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html#skill 下载地址:http://mozilla.gith ...

  9. 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo

    Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...

随机推荐

  1. 洛谷P4556 雨天的尾巴 线段树

    正解:线段树合并 解题报告: 传送门! 考虑对树上的每个节点开一棵权值线段树,动态开点,记录一个max(num,id)(这儿的id,define了一下,,,指的是从小到大排QAQ 然后修改操作可以考虑 ...

  2. P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp

    正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...

  3. 第一章 初识windows程序

    window 操作系统中,处处是窗体 简单 强大 方便 灵活 步骤 新建项目 项目类型 visual C#项目 模板 window应用程序 用partial 将同一个窗体的代码分开放在两个文件中: 一 ...

  4. zabbix准备:nginx安装

    一.nginxs的三个依赖包 1.zlib库.  gzip 模块需要 zlib 库   ( 下载: http://www.zlib.net/ ) gzip(GNU-ZIP)是一种压缩技术.经过gzip ...

  5. jenkins的pipeline的使用

    1.安装Pipeline Maven Integration Plugin 2.新建任务 3.编写pipeline代码 node { stage('get clone') { checkout([$c ...

  6. MySQL 多源复制(Mulit-Source Replication)

    MySQL多源复制方案        看复制源Master_1的同步状态:SHOW SLAVE STATUS FOR CHANNEL 'Master_1'\G 查看复制源Master_2的同步状态:S ...

  7. SSH服务知识

    1.ssh介绍 SSH 是 Secure Shell Protocol 的简写,由 IETF 网络工作小组(Network Working Group )制定:在进行数据传输之前,SSH先对联机数据包 ...

  8. [py]__name__ 属于哪个文件

    name: 属于哪个文件 文件的 main 类的 class Person(object): """ 定义一个类 """ count = 1 ...

  9. (转)面试必备技能:JDK动态代理给Spring事务埋下的坑!

    一.场景分析 最近做项目遇到了一个很奇怪的问题,大致的业务场景是这样的:我们首先设定两个事务,事务parent和事务child,在Controller里边同时调用这两个方法,示例代码如下: 1.场景A ...

  10. map的使用方式之一。

    map有返回值 foreach 没得.. 得到结果 可以把里面的值以数组的方式取出来: 举例: