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();
}
相关推荐
爱签AI电子合同33 分钟前
电子合同上手成本怎么测?易用性维度专项测评
服务器·人工智能·智能合约·企业微信
aixingkong9213 小时前
Nvidia为例 XPU的Multi-Host、Socket Direct 、GPUDirect、RDMA 技术点分析
服务器·网络·硬件架构·硬件工程
Quz4 小时前
QML TreeView:排序与搜索过滤
qt
Quz5 小时前
QML TreeView:基础树视图与自定义委托
qt
雯宝5 小时前
mnt_init 函数
linux
Junfeng的技术笔记11 小时前
基于 C++/Qt 的雷达回波信号检测与测距仿真系统
qt
律宏阔11 小时前
WSL Docker 端口明明空闲,但就是绑不上端口
linux·windows
律宏阔11 小时前
WSL 突然断网,无法 ping 内网或外网
linux·windows
穷人小水滴11 小时前
用容器编译 VirtualBox 虚拟机软件 (ArchLinux, podman)
linux·容器·virtualbox
Quz11 小时前
QML TableView:自定义样式与排序表格
qt