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();
}
相关推荐
Lucas. Wáng8 小时前
Qt学习之旅
c++·qt
蜗牛一步步往上爬8 小时前
第十一章 构建基本脚本
linux
星恒随风8 小时前
从0实现C++ AI大模型接入SDK(二):AI知识科普——从图灵测试到ChatGPT,人工智能的发展历程
linux·c++·人工智能·笔记·chatgpt
飞奔的瓜牛8 小时前
Linux 数据盘分区、格式化与自动挂载完整实践
linux·运维·服务器
Lucas. Wáng10 小时前
Linux网络编程之网络套接字
linux·服务器·网络
数字新视界10 小时前
动环智能监控在机房管理中的智能应用与安全保障
服务器·数据中心·机房·环境管理·环控系统
进击的荆棘10 小时前
Linux网络——Socket编程TCP
linux·运维·服务器·网络·tcp/ip
大今野11 小时前
2026 专转本计算机|Linux CentOS7 软件包管理:yum 仓库配置与常用命令考点全解(附例题)
linux·运维·服务器·专转本
SeanQhl11 小时前
openEuler 下 Docker 静态安装与容器基础操作
linux·docker·云原生·容器·openeuler
无奈笑天下11 小时前
Wine适配Windows程序常见故障标准处理流程
linux·运维·服务器·windows