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();
}
相关推荐
结衣结衣.3 分钟前
【Linux】命名管道的妙用:实现进程控制与实时字符交互
linux·运维·开发语言·学习·操作系统·交互
IMPYLH10 分钟前
Linux 的 groups 命令
linux·运维·服务器·bash
Lugas Luo19 分钟前
SATA 协商流程深度分析 (基于 libata 与 AHCI 控制器)
linux·嵌入式硬件
RisunJan24 分钟前
Linux命令-mysqladmin(MySQL服务器管理客户端)
linux·服务器·mysql
何中应37 分钟前
MindMap问题
运维·服务器·xmind
不才小强1 小时前
Linux网络调试工具:curl与抓包实战
linux·运维·网络
长不大的小Tom1 小时前
计算机软件资格考试——数据库系统工程师 考点分析
服务器·sql
我还为发觉1 小时前
Linux 监控可视化|Prometheus+Node Exporter 一键部署教程
linux·运维·prometheus
zylyehuo2 小时前
在 Ubuntu 下进行磁盘分卷
linux
咕噜签名-铁蛋2 小时前
云部署 OpenClaw 与飞书无缝对接完整指南
服务器·人工智能·飞书