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();
}
相关推荐
北风toto4 分钟前
log4j中文日志乱码问号-Linux启动jar包,输出中文日志变成问号?
linux·log4j·jar
实心儿儿11 分钟前
Linux —— 库的制作和原理(3)
linux·运维·服务器
yyuuuzz14 分钟前
独立站部署的几个常见技术问题
运维·服务器·网络·云计算·aws
十子木17 分钟前
linux 安装claude code
linux
努力努力再努力wz18 分钟前
【Qt入门系列】第一个 Qt Widgets 程序:项目创建、UI 文件、Hello World、对象树与 qDebug 日志
java·c语言·开发语言·数据结构·c++·qt·ui
a珍爱上了a强21 分钟前
配置uboot启动参数,linux启动过程打印每个模块初始化的耗时时间
linux·运维·服务器
Hua-Jay23 分钟前
OpenCV联合C++/Qt 学习笔记(十五)----形态学操作及应用
c++·笔记·qt·opencv·学习·计算机视觉
程序员老舅30 分钟前
深入底层:Linux MMU 工作原理全解
linux·服务器·网络·c++·linux内核·内存管理·linux内存
dishugj34 分钟前
SAP HANA数据库文件目录说明
服务器·数据库·oracle
chao1898441 小时前
Qt Modbus TCP 通讯源码
qt·tcp/ip·命令模式