【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. HTML5 自定义属性

    先声明  HTML5的自定义属性浏览器支持性不太好   目前只有firefox6+和chrome浏览器支持 元素除了自带的属性外 另外也可以加自定义属性   不过需要在前面加上data- 下面举个例子 ...

  2. Hibernate 和 MyBatis 的区别

    Hibernate 和 MyBatis 的增.删.查.改,对于业务逻辑层来说大同小异,对于映射层而言 Hibernate 的配置不需要接口和 SQL,相反 MyBatis 是需要的.对于 Hibern ...

  3. FastReport快速安装教程

    安装后需要覆盖的文件全部复制到安装目录 替换后的安装目录 选中Recompile右键必须以管理员运行 看图选择 编译后,需要汉化的话看下图选择 怎么添加Library直接看图按顺序进行 选择insta ...

  4. LigerUi折叠与展开

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  5. Flappy Bird

    在网上学习了下“65行 JavaScript 代码实现 Flappy Bird 游戏”(http://blog.jobbole.com/61842/),main.js 如下: // Initializ ...

  6. 微信小程序实现简单的树形图treeview

    H5有很多树形图(树状图)的组件,echarts也有.比如像bootstrap的treeview,定制性很强.不过这些都无法方便地为小程序所用,除非整个页面用H5搭建再用webview框进去,有点粗暴 ...

  7. Spring MVC定时服务

    spring-mvc-config.xml <context:component-scan base-package="com.bf" ></context:co ...

  8. [LeetCode] Backtracking Template for (Subsets, Permutations, and Combination Sum)

    根据issac3 用Java总结了backtracking template, 我用他的方法改成了Python. 以下为template. def backtrack(ans, temp, nums, ...

  9. HTTPS安全不?

    首先,它是什么?我的理解是一开始进行SSL握手,商量好将要使用哪些加密算法来通讯,或者加密方法后使用非对称的加密方法,交互一下随机数,加上一个pre-master-secrect的,然后服务端利用私钥 ...

  10. 遇到问题---hosts不起作用问题的解决方法

    c:\WINDOWS\system32\drivers\etc\hosts 文件的作用是添加 域名解析 定向 比如添加 127.0.0.1  www.baidu.com 那我们访问www.baidu. ...