Qt添加Dialog对话框

Qt版本:5.12.12

1.添加【模块】

Base class:可以选择QDialog、QWidget、QMainWindow

会自动生成MyDialog.h和MyDialog.cpp文件以及MyDialog.ui文件,

2.添加代码:

(1)TestDialog.h

复制代码
#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_TestDialog.h"

#include "MyDialog.h"

class TestDialog : public QMainWindow
{
    Q_OBJECT

public:
    TestDialog(QWidget *parent = nullptr);
    ~TestDialog();
    MyDialog dlg;
public slots:
    void OpenDialog();

   
private:
    Ui::TestDialogClass ui;
};

(2)TestDialog.cpp

复制代码
#include "TestDialog.h"

TestDialog::TestDialog(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
   //连接信号和槽
    connect(ui.pushButton_Open, SIGNAL(clicked()), this, SLOT(OpenDialog()));
}

TestDialog::~TestDialog()
{}

void TestDialog::OpenDialog()
{
    dlg.show();
}
相关推荐
Highcharts.js21 小时前
教程:基于 React + Highcharts 构建一个单页应用程序、按需数据拉取与图表渲染
开发语言·前端·数据结构·react.js·前端框架·highcharts·页面应用
头发还在的女程序员1 天前
医院陪诊管理系统怎么选择?——2026 年选型避坑与架构参考
java·开发语言·陪诊系统·陪诊app·医院陪诊陪护
爱写代码的小朋友1 天前
从零开始学 Win32 API:C++ 窗口编程实战(VS Code + MinGW-w64 命令行详解)
开发语言·c++
果汁华1 天前
Function Calling 与 Python 实战完整指南
开发语言·网络·python
小小晓.1 天前
C++:语句和作用域
开发语言·c++
wanderist.1 天前
Lambda表达式在算法竞赛中的应用
java·开发语言·算法
海天鹰1 天前
PHP上传文件
android·开发语言·php
Yeauty1 天前
渲染成图再 CLI 拼接,还是进程内直推?Rust 帧到视频的两条路
开发语言·rust·音视频
geovindu1 天前
CSharp: Breadth First Search Algorithm and Depth First Search Algorithm
开发语言·后端·算法·c#·.net·搜索算法
库克克1 天前
【C++】set 与multiset
开发语言·c++