QDialog 使用Demo
【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的更多相关文章
- QT 随笔目录
[1]基础部分 <信号和槽机制> <信号与槽知识点> <QString 与 string转换> <QT 继承QWidget && 继承QDia ...
- qt5之设置无边窗口移动
Note qt version: 5.12 qt creator: 4.13 本文将介绍 设置无边窗口和设置窗口的移动 你要知道: QDialog 和 QMainWindow都是 QWidget的派生 ...
- QT 入门 -QApplication QPushButton QDialog Ui类型的手工使用
QT 1.工具 assistant 帮助文档 qtconfig QT配置工具 qmake QT的make与项目文件智能创建工具 uic UI界面的设计文件的编译工具 mo ...
- Qt Creator简单计算器的Demo
小编在期末数据结构课设中遇到要做可视化界面的问题,特意去学习了一下Qt的用法,今天就来给大家分享一下. 我用的是Qt5.80,当然这只是一个简易的计算器Demo,,请大家勿喷. 首先我创建了一个Qt ...
- QDialog对话框
QDialog对话框,用来实现那些只是暂时存在的用户界面,是独立的窗口,但通常也有父窗口对话框有模态和非模态两种,,非模态对话框的行为和使用方法都类似于普通的窗口,模态对话框则有所不同,当模态对话框显 ...
- 通过一个demo了解Redux
TodoList小demo 效果展示 项目地址 (单向)数据流 数据流是我们的行为与响应的抽象:使用数据流能帮我们明确了行为对应的响应,这和react的状态可预测的思想是不谋而合的. 常见的数据流框架 ...
- 很多人很想知道怎么扫一扫二维码就能打开网站,就能添加联系人,就能链接wifi,今天说下这些格式,明天做个demo
有些功能部分手机不能使用,网站,通讯录,wifi基本上每个手机都可以使用. 在看之前你可以扫一扫下面几个二维码先看看效果: 1.二维码生成 网址 (URL) 包含网址的 二维码生成 是大家平时最常接触 ...
- 在线浏览PDF之PDF.JS (附demo)
平台之大势何人能挡? 带着你的Net飞奔吧!:http://www.cnblogs.com/dunitian/p/4822808.html#skill 下载地址:http://mozilla.gith ...
- 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
Maven+springboot+阿里大于短信验证服务 纠结点:Maven库没有sdk,需要解决 Maven打包找不到相关类,需要解决 ps:最近好久没有写点东西了,项目太紧,今天来一篇 一.本文简介 ...
随机推荐
- SQL server 2005数据库的还原与备份
一.SQL数据库的备份: 1.依次打开 开始菜单 → 程序 → Microsoft SQL Server 2005→SQL Server Management Studio ,这里我以UMVTEST命 ...
- oracle日志归档空间清理
进入机器,设置环境变量,如: export ORACLE_HOME=/main/app/oracle/product//db_1 export ORACLE_SID=devdb 然后切换oracle用 ...
- mvn install package区别
package是把jar打到本项目的target下,而install时把target下的jar安装到本地仓库,供其他项目使用
- 20181211 Oracle Parallel
如下用Select作为参考, Select 在sql server中如果直接查询大量的数据,方式为给列增加Index,可以提高效率.如果查询数据量非常大的时候其实效率依旧不高,而且index在增删改中 ...
- Linux小脚本
将固定的换包步骤,做成脚本replacePackage.sh,赋予执行权限(chmod +x replacePackage.sh).这样小小自动化也能节约时间呀. replacePackage.s ...
- 【1】vue/cli 3.0 脚手架 及cube-ui 安装
安装 Vue CLI 需要 Node.js 8.9 或更高版本 (推荐 8.11.0+).你可以使用 nvm 或 nvm-windows在同一台电脑中管理多个 Node 版本. 检查node版本: $ ...
- bcolz的新操作
1.直接修改 eg:把data.bcolz文件中A列为0的数据填充为1000. data = bcolz.open("data.bcolz", "a") #以& ...
- [js]顶部导航和内容区布局
自己实现顶部导航布局--内容显示 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- 查看npm仓库版本号
http://repo.inspur.com:8081/artifactory/webapp/#/artifacts/browse/simple/General/thirdparty iop 找到现在 ...
- (转)Fabric CA环境的集成
PS:因为我部署的是集群(4peer+1order),需要为order,org1,org2分别建立一个CA,拿org1使用举例,获取org1根证书私钥名称:PRIVATE_KEY.sh #!/bin/ ...