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();
}
相关推荐
二进制person1 小时前
JavaEE初阶 --网络编程
linux·服务器·网络
Cyber4K1 小时前
【妙招系列】Harbor 镜像私有仓库搭建手册
linux·云原生·容器
娇娇yyyyyy1 小时前
QT编程(17): Qt 实现自定义列表模型
开发语言·qt
Irissgwe2 小时前
进程间通信
linux·服务器·网络·c++·进程间通信
创世宇图2 小时前
阿里云Alibaba Cloud Linux 4 LTS 64位生产环境配置-Nginx
linux·nginx
岁岁种桃花儿2 小时前
AI超级智能开发系列从入门到上天第四篇:AI应用方案设计
java·服务器·开发语言
待续3013 小时前
OpenClaw 安装及使用教程(Windows / macOS / Linux)
linux·windows·macos
创世宇图3 小时前
Alibaba Cloud Linux 安装生产环境-mysql
linux·mysql
TEC_INO3 小时前
嵌入式 Linux 开发知识总结
linux·运维·服务器
肖恭伟4 小时前
Cursor Superpowers 零基础开发 Qt 界面
开发语言·qt