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·开发语言·学习
qq_401700415 小时前
Qt 中文乱码的根源:QString::fromLocal8Bit 和 fromUtf8 区别在哪?
开发语言·qt
佑白雪乐6 小时前
<Linux基础第10集>复习前面内容
linux·运维·服务器
春日见6 小时前
自动驾驶规划控制决策知识点扫盲
linux·运维·服务器·人工智能·机器学习·自动驾驶
暮云星影7 小时前
四、linux系统 应用开发:UI开发环境配置概述 (三)
linux·ui·arm
迷途知返-7 小时前
服务器——那些年我踩过的坑
linux
机器视觉知识推荐、就业指导8 小时前
Qt 和 C++,是不是应该叫 Q++ 了?
开发语言·c++·qt
landonVM8 小时前
Linux 上搭建 Web 服务器
linux·服务器·前端
liu****8 小时前
三.Qt图形界面开发完全指南:从入门到掌握常用控件
开发语言·c++·qt
云游云记8 小时前
nesbot/carbon 常用功能总结
linux·运维·服务器