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();
}
相关推荐
Java程序之猿7 小时前
Linux使用U盘安装centos及报错You might want to saue “/run/initramfs/rdsosreport.txt“ 处理
linux·运维·服务器
少控科技7 小时前
QT高阶日记01
开发语言·qt
CC.GG7 小时前
【Linux】进程概念(五)(虚拟地址空间----建立宏观认知)
java·linux·运维
L1624767 小时前
通用 Linux 系统存储选型总手册(MBR ,GPT,ext4,xfs)
linux·服务器
明洞日记8 小时前
【软考每日一练008】Web 服务器性能测试指标
运维·服务器·操作系统·软考
木千8 小时前
Qt全屏显示时自定义任务栏
开发语言·qt
习惯就好zz8 小时前
[实战笔记] 从 Qt 5.12.9 跨越到 Qt 6.x 完美迁移指南 (Windows + VS)
windows·qt·msvc·qt5·qt6·迁移
以太浮标8 小时前
华为eNSP模拟器综合实验之- AC+AP无线网络调优与高密场景
java·服务器·华为
真的想上岸啊8 小时前
1、全志h616板子介绍
linux
2401_890443028 小时前
Linux线程概念与控制
linux