【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. java 线程(七)等待与唤醒

    package cn.sasa.demo5; public class Resources { private String name; private boolean gender; //标记 pu ...

  2. 使用poi读写excel文件

    使用poi库测试了一下读取excel文件,效果不错,跟大家分享一下. 第一列是数值型,第二列是字符型,代码如下: package poi; import java.io.FileInputStream ...

  3. Maven中groupId和artifactId的含义

    groupId和artifactId被统称为“坐标”是为了保证项目唯一性而提出的,如果你要把你项目弄到maven仓库去,你想要找到你的项目就必须根据这两个id去查找.groupId是项目组织唯一的标识 ...

  4. linux 查看网卡流量:sar

    sar(System Activity Reporter 系统活动情况报告)是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,但我们一般用来监控网卡流量 # 安装 ...

  5. laravel出现No hint path defined for [sudosu]的解决方法

    今天ytkah在部署laravel项目时出现了No hint path defined for [sudosu]的问题,大概意思是没有定义sudosu的提示路径,那我们找一下配置文件有没相关设置,看到 ...

  6. Laravel展示产品-CRUD之show

    上一篇讲了Laravel创建产品-CRUD之Create and Store,现在我们来做产品展示模块,用到是show,①首先我们先修改controller,文件是在/app/Http/Control ...

  7. 20170921 DEV功能页面

    环境:vs2013 DEV第三方控件 后端使用Linq to sql , lambda 表达式 页面格式

  8. 基于TensorFlow的简单验证码识别

    TensorFlow 可以用来实现验证码识别的过程,这里识别的验证码是图形验证码,首先用标注好的数据来训练一个模型,然后再用模型来实现这个验证码的识别. 生成验证码 首先生成验证码,这里使用 Pyth ...

  9. react 首页加载loading

    首页加载loading,放在#root里面,代码如下: <!DOCTYPE html> <html lang="en"> <head> < ...

  10. 微信小程序使用阿里图标-iconfont

    步骤一:下载项目图标 步骤二:解压文件,重命名 iconfont.css为 iconfont.wxss ,并复制 到项目 static文件夹 icon文件夹下                     ...