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();
}
相关推荐
_守一14 分钟前
UE DS+Nakama进行游戏服务器开发(1)源码编译nakama
服务器·游戏
Joseph Cooper15 分钟前
Linux HID 子系统实战:从虚拟键盘到 input 事件上报
linux·c语言·计算机外设
原来是猿16 分钟前
【Socket编程预备知识】
linux·运维·服务器·网络
萧行之1 小时前
Docker部署Loki+Grafana+Vector实现全服务器日志监控(含N8N/SSH/Fail2ban监控)
服务器·docker·grafana
learning-striving1 小时前
Ubuntu26.04下载安装教程
运维·服务器·vmware·虚拟机
__beginner__1 小时前
CentOS 磁盘占用异常排查与处理手册(df 高、du/ncdu 低)
linux·运维·centos
坚持就完事了2 小时前
YARN资源管理器
大数据·linux·hadoop·学习
Joseph Cooper3 小时前
Linux regmap 子系统实战:在驱动中 dump PMIC 寄存器定位供电问题
linux·运维·服务器
计算机安禾3 小时前
【Linux从入门到精通】第35篇:容器化技术预备——Docker安装与基本概念
linux·运维·docker
子木HAPPY阳VIP3 小时前
信创UOS,Docker 完整操作部署(Dockerfile部署方式)&排错整合
linux·运维·redis·nginx·docker·容器·tomcat