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();
}
相关推荐
桌面运维家2 分钟前
Windows/Linux双启动:BIOS/UEFI多配置桌面创建指南
linux·运维·windows
xlp666hub7 分钟前
【Linux驱动实战】:字符设备驱动之内核态与用户态数据交互
linux·面试
阿达_优阅达9 分钟前
告别手工对账:xSuite 如何帮助 SAP 企业实现财务全流程自动化?
服务器·数据库·人工智能·自动化·sap·企业数字化转型·xsuite
久绊A13 分钟前
服务器新硬盘初始化与挂载
linux·挂载
IMPYLH25 分钟前
Linux 的 chroot 命令
linux·运维·服务器
克莱因35843 分钟前
Linux Cent OS7 at定时任务
linux·运维·服务器
RisunJan43 分钟前
Linux命令-make(GNU的工程化编译工具)
linux·运维·gnu
闲猫1 小时前
Linux 历史命令(history)
linux·运维·chrome
程序员小董1 小时前
从 RocksDB 定时器出发:手写一个通用的 Linux 高精度定时器
linux·服务器
旺仔.2912 小时前
线程安全 详解
linux·计算机网络·安全