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();
}
相关推荐
海天鹰11 小时前
【免费】PHP主机=域名+解析+主机
服务器
哇哈哈202112 小时前
信号量和信号
linux·c++
不是二师兄的八戒12 小时前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
芝士雪豹只抽瑞克五12 小时前
Nginx 高性能Web服务器笔记
服务器·nginx
失重外太空啦12 小时前
Tomcat
java·服务器·tomcat
一个人旅程~12 小时前
如何用命令行把win10/win11设置为长期暂停更新?
linux·windows·经验分享·电脑
Henry Zhu12313 小时前
数据库:并发控制基本概念
服务器·数据库
茶杯梦轩13 小时前
从零起步学习并发编程 || 第九章:Future 类详解及CompletableFuture 类在项目实战中的应用
服务器·后端·面试
2302_7995257413 小时前
PCI、PCIe 和 NVLink
linux
ZeroNews内网穿透13 小时前
谷歌封杀OpenClaw背后:本地部署或是出路
运维·服务器·数据库·安全