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();
}
相关推荐
加油码10 小时前
动静态库的链接底层原理(进阶版)
linux·c++
s_w.h10 小时前
【 计网 】计算机网络基础
服务器·计算机网络
程与留10 小时前
06_Qt 常用数据类型与容器:QString、QList、QVector、QMap 的性能与实现分析
数据结构·qt
H_oRIZoN_11 小时前
Linux入门DAY23(C语言树形结构)
linux·c语言·数据结构
kdxiaojie11 小时前
Linux USB驱动阅读笔记(1)
linux·笔记·学习·usb
JacksonMx11 小时前
Java CompletableFuture 异步编程实战:从入门到架构师避坑指南
linux·数据库·python
byte轻骑兵12 小时前
【BlueZ 】蓝牙 SDAP 协议入门:BlueZ 中设备服务发现的基础逻辑
linux·人工智能·bluez·电脑蓝牙·嵌入式蓝牙
mounter62512 小时前
GCCRS 突破与 Rust 入核:Linux 工具链的重大变革
linux·开发语言·rust·linux kernel·kernel
怪侠_岭南一只猿12 小时前
[简单理解]小龙虾是怎么一回事?
运维·服务器·ai
海兰12 小时前
【应用】Wastnet 框架的 SSE (Server-Sent Events)从协议原理到实践指南
运维·服务器·人工智能