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();
}
相关推荐
哈哈浩丶6 分钟前
存储相关知识②—eMMC协议
linux·驱动开发·emmc
geshifei7 分钟前
Sched_ext 回调深度解析(一):init_task —— 每个任务走进调度器的第一道门(6.18.26)
linux·ebpf
纽格立科技14 分钟前
数字广播快问快答:从“有没有载波“到“听上去像噪声“
服务器·车载系统·信息与通信·传媒
没文化的阿浩19 分钟前
【Linux系统】Ext系列文件系统
linux·运维·电脑
红茶要加冰25 分钟前
九、文本处理三剑客——sed
linux·运维·服务器·正则表达式·shell
落羽的落羽29 分钟前
【项目】C++从零实现JsonRpc框架——项目引入
linux·服务器·开发语言·c++·人工智能·算法·机器学习
菜_小_白39 分钟前
tcpdump
linux·网络·测试工具·http·tcpdump
折翅嘀皇虫1 小时前
【无标题】steal_work_thread_pool
服务器·前端·算法
zzzsde1 小时前
【Linux】线程概念与控制(3):线程ID&&C++封装线程
linux·运维·服务器·开发语言·算法
消失的旧时光-19431 小时前
C 语言如何实现“面向对象”?—— 从 struct + 函数指针,到 Linux 内核设计思想
linux·c语言·开发语言