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();
}
相关推荐
ling-4517 分钟前
ifconfig 不显示 Linux 虚拟机常规网卡的 IP 地址
服务器·网络·php
黎明晓月30 分钟前
‌CentOS 7.9 安装 Docker 步骤
linux·docker·centos
菜鸟xy..39 分钟前
winhex软件简单讲解,虚拟磁盘分区介绍
linux·运维·服务器
网硕互联的小客服42 分钟前
如何排查服务器内存泄漏问题
linux·运维·服务器·安全·ssh
Evoxt 益沃斯1 小时前
How to enable Qemu Guest Agent for Virtual Machines
linux·运维·服务器·qemu
钟离墨笺1 小时前
【Linux】【网络】UDP打洞-->不同子网下的客户端和服务器通信(未成功版)
linux·服务器·网络
llkk星期五1 小时前
ubuntu 22.04附加驱动安装NVIDIA显卡驱动重启后无WiFi蓝牙等问题
linux·ubuntu
CVer儿1 小时前
ubuntu挂载固态硬盘
linux·运维·ubuntu
music&movie1 小时前
Win11安装VMware和Ubuntu并使用ssh访问部署模型
linux·ubuntu·ssh
程序员JerrySUN1 小时前
在 Ubuntu 20.04 上交叉编译 Qt 5 应用,使其可在 Windows 运行
windows·qt·ubuntu