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();
}
相关推荐
夏玉林的学习之路1 天前
如何远程连接服务器
运维·服务器
风曦Kisaki1 天前
#Linux数据库管理Day06:主从同步与MaxScale读写分离
linux·运维·数据库
小楼昨夜又东风1261 天前
使用python快速拉包
linux
qq_401700411 天前
Qt QSS 完全入门写出漂亮界面以及解决样式不生效问题
开发语言·qt
影寂ldy1 天前
C# try-catch 异常处理全套笔记
服务器·数据库·c#
fei_sun1 天前
黑洞路由(Null Route/空接口路由)
服务器·前端·javascript
Tipriest_1 天前
ubuntu创建和更换当前swap大小
linux·运维·ubuntu
旖-旎1 天前
QT系统篇(5)(下)
开发语言·c++·qt
Irissgwe1 天前
第四章 QT窗口
qt
WI8LbH7881 天前
Ubuntu 部署Harbor
linux·运维·ubuntu