01.QT中点击弹出新页面

 调用者类定义CallWidget.h



#pragma once

#include <QtWidgets/QMainWindow>
#include "ui_CallWidget.h"
#include "widget.hpp"

class CallWidget : public QMainWindow
{
    Q_OBJECT

public:
    CallWidget(QWidget *parent = Q_NULLPTR);
    ~CallWidget();

public slots:
    void on_btn_slot(bool);

private:
    Ui::CallWidgetClass ui;
    
    //需要被弹出的页面
    Widget * w1;
};

类CallWidget.cpp代码

#include "CallWidget.h"
#include <QDebug>
#include "widget.hpp"

CallWidget::CallWidget(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	resize(800, 600);

	//构造器中,不能添加this,因为this,表示这个widget属于他的父亲.
	w1 = new Widget();
	connect(ui.pushButton, SIGNAL(clicked(bool)), this, SLOT(on_btn_slot(bool)));
}

CallWidget::~CallWidget()
{
	qDebug() << "call ~callWidget";
    delete w1;
}

void CallWidget::on_btn_slot(bool)
{
	qDebug() << "on_btn_slot";

	w1->resize(300, 200);
	w1->show();

}

  被调用者widget.cpp

#include "widget.hpp"
#include "QDebug"

Widget::Widget(QWidget * parent) : QWidget(parent) {
	ui.setupUi(this);
	qDebug() << "welcome to widget";
}

Widget::~Widget() {
	/*qDebug() << "before delete ui";
	delete &ui;
	qDebug() << "after delete ui";*/
}

  注意点:

        widget页面,手动关闭时, 并不会 调用他自身的析构函数,所以想要释放widget 内存,只能在主页面 的析构函数中进行调用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

guangshui516

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值