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();
}
相关推荐
三言老师4 小时前
秘诀-如何远程SSN访问家里的八台电脑(frp 实操方案)
linux·运维·ssh
躺不平的理查德5 小时前
ARCH与交叉编译器的关系
服务器·arm
举手6 小时前
Dispatcher模块剖析
linux·c++
谢慧琼6 小时前
2026零基础做企业网站,低成本搭建官方网站
服务器·前端·javascript
allforgood7 小时前
运行容器
linux
byxdaz7 小时前
QT中服务使用
开发语言·qt
Light_It8 小时前
Linux 内核参数 pci-stub.ids=
linux·kernel
RisunJan8 小时前
Linux命令-scriptreplay(终端会话回放)
linux·运维·chrome
spencer_tseng8 小时前
[kylin & linux] install docker
linux·docker·kylin
x²+(y-√³x²)²=19 小时前
Linux打包文件到Windows,文件/文件类型丢失
linux·运维·windows