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();
}
相关推荐
liulilittle4 分钟前
Linux Swap 文件配置与持久化(虚拟内存)
linux·运维·服务器
青梅橘子皮14 分钟前
Linux---进程控制(2)(进程程序替换)
linux·c++·算法
零陵上将军_xdr21 分钟前
从沙子到CPU——计算机硬件基础入门
linux·运维·硬件架构
vortex523 分钟前
Linux 命令工具箱:util-linux 与 GNU Coreutils
linux·运维·gnu
荒--37 分钟前
MSF 使用
linux·运维·服务器
狮子再回头1 小时前
relhat9.1 sshd配置
linux·服务器·网络
小短腿的代码世界1 小时前
Qt对象树析构链与智能指针协同:零泄漏内存管理架构
开发语言·qt·架构
不爱编程的小陈1 小时前
深入解析 Go 网络 I/O 的底层引擎:从 epoll 到 netpoll
服务器·网络·golang
烁3472 小时前
liunx命令不完整版
linux·运维·服务器
vsropy2 小时前
cmake版本不对不能直接删/无法source
linux·运维·服务器