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 分钟前
openclaw.json配置示例
服务器·json·openclaw
飞Link5 分钟前
深度掌控 Agent 调试:LangGraph 本地服务器与 Studio 核心指南
运维·服务器·jvm
冉佳驹19 分钟前
Qt【第五篇】——— QMainWindow 核心组件与对话框开发详解
qt·qdialog·qtoolbar·qstatusbar·qdockwidget·qmenubar
古月方枘Fry32 分钟前
三层交换+单臂路由+ACL网络配置
服务器·网络·智能路由器
驾驭人生33 分钟前
ASP.NET Core 实现 SSE 服务器推送|生产级实战教程(含跨域 / Nginx / 前端完整代码)
服务器·前端·nginx
KOYUELEC光与电子努力加油1 小时前
JAE日本航空电子推出满足汽车市场小型防水最新需求的MX80系列连接器
服务器·科技·单片机·汽车
123过去2 小时前
hashid使用教程
linux·网络·测试工具·安全
cpp_learners2 小时前
银河麒麟V10+飞腾D2000/8处理器+在线源码编译安装Firefox78.0指南
qt·firefox·麒麟
C+++Python2 小时前
Linux/C++多进程
linux·运维·c++
XZY0282 小时前
如何使用grpc
运维·服务器