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();
}
相关推荐
shixuzhimeng2 分钟前
FTP服务器项目
linux·网络·ftp
Chris-zz5 分钟前
Linux:线程概念与控制
linux·运维
864记忆11 分钟前
OD车牌号获取流程
qt
剑神一笑19 分钟前
Linux chown 命令详解:从 inode 到实战
linux·运维·服务器
MIXLLRED25 分钟前
随笔——在 Ubuntu 22.04 中查看 Markdown (.md) 文件
linux·运维·ubuntu·markdown
STDD33 分钟前
Linux cgroup v2 资源控制实战:限制进程 CPU/内存/IO,systemd slice 管理
linux·运维·服务器
Latticy43 分钟前
内网渗透-横向移动-密码喷洒攻击和域内用(kerbrute使用)
运维·服务器·网络·内网渗透·内网
kukubuzai1 小时前
Docker Note
linux·运维·docker
网络研究院2 小时前
Proton Drive采用OpenPGP加密,上传速度提升300%
服务器·网络·安全·proton drive·openpgp
Ltd Pikashu2 小时前
insmod 加载内核模块 —— sys_init_module 源码剖析
linux·kernel·insmod