QT 实现窗口的跳转

复制代码
#include <QApplication>
#include <QDebug>
#include <QWidget>
#include <QTextEdit>
#include <QLineEdit>
#include <QPushButton>
#include <QBoxLayout>
#include <QLabel>

class Widget:public QWidget{
    QPushButton* but;
    Widget* other;
public:
    Widget();
    void setother(Widget& w);
    void buttext(const char* text);
    void click();
};

Widget::Widget() : other(NULL)
{
     but = new QPushButton(this);
     QVBoxLayout lay;
     lay.addWidget(this);
     QObject::connect(but, &QPushButton::clicked, this, &Widget::click);
 }

void Widget::setother(Widget& w)
{
    other=&w;
}

void Widget::buttext(const char* text)
{
    but->setText(text);
}

void Widget::click()
{
    this->hide();
    if (other) {
        other->show();
    }
}

int main(int argc,char** argv)
{
    QApplication app(argc,argv);

    Widget w1,w2;
    w1.buttext("w1.but");
    w2.buttext("w2.but");
    w1.setother(w2);
    w2.setother(w1);

    w1.show();

    return app.exec();
}
相关推荐
kblj555518 分钟前
学习Linux——网络基础管理
linux·网络·学习
前端世界19 分钟前
用Python打造智能成绩分析系统:从异常处理到断言验证的全流程实战
服务器·数据库·python
小王C语言42 分钟前
Linux基础开发工具----yum、vim和gcc/g++
linux·运维·服务器
_w_z_j_1 小时前
Linux----文件系统
linux·运维·服务器
SKYDROID云卓小助手2 小时前
无人设备遥控器之数字图传技术
运维·服务器·单片机·嵌入式硬件·fpga开发
努力努力再努力wz2 小时前
【Linux进阶系列】:线程(上)
java·linux·运维·服务器·数据结构·c++·redis
java 乐山2 小时前
蓝牙网关(备份)
linux·网络·算法
2301_803554522 小时前
面试后查缺补漏--cmake,makefiles,g++,gcc(自写精华版)
linux·运维·服务器
煤球王子2 小时前
浅学任务调度
linux
102400243 小时前
ubuntu系统中 jupyter Kernel 频繁崩溃原因
linux·运维·服务器