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();
}
相关推荐
C语言小火车43 分钟前
QT面试题:内存管理与对象生命周期
开发语言·qt·面试
Stringzhua7 小时前
Linux多网卡组Bond0Bond1Bond4
运维·服务器·网络
暮云星影7 小时前
十二、buildroot系统 adb登录权限设置
linux·arm开发·adb
HHONGQI1237 小时前
Linux 基础入门操作 前言 VIM的基本操作 2
linux·运维·服务器·vim
追烽少年x7 小时前
使用QAction编辑器添加QAction到ui里
qt
王伯爵7 小时前
接入网和核心网之间的承载网详细介绍
服务器·网络·数据库
qq_543248528 小时前
Linux网络配置与测试
linux·运维·网络
钡铼技术物联网关8 小时前
下一代楼宇自控的中枢神经:ARM终端的生态
大数据·linux·人工智能
依旧风轻8 小时前
深入理解 rsync daemon 模式(守护进程)
linux·ios·rsync·daemon·sqi
小峰编程9 小时前
谈Linux之磁盘管理——万字详解
linux·运维·服务器·经验分享·笔记·centos·运维开发