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();
}
相关推荐
Andya_net14 分钟前
网络安全 | 深入了解 X.509 证书及其应用
服务器·安全·web安全
纳于大麓22 分钟前
Kotlin基础语法
linux·windows·kotlin
九皇叔叔28 分钟前
Linux Shell 正则表达式中的 POSIX 字符集:用法与实战
linux·运维·正则表达式
東雪蓮☆1 小时前
K8s 平滑升级
linux·运维·云原生·kubernetes
---学无止境---2 小时前
Linux中进程创建和缓存对象初始化fork_init、proc_caches_init和buffer_init
linux
qq_183802872 小时前
Linux内核idr数据结构使用
linux·运维·服务器
Algebraaaaa2 小时前
什么是前端、后端与全栈开发,Qt属于什么?
开发语言·前端·qt
大美B端工场-B端系统美颜师2 小时前
工控软件开发选择难?Electron、Qt、WPF 对比
qt·electron·wpf
码农-小林3 小时前
使用leaflet库加载服务器离线地图瓦片(这边以本地nginx服务器为例)
运维·服务器·nginx
噜啦噜啦嘞好3 小时前
Linux:库制作与原理
linux·运维·服务器