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();
}
相关推荐
缘友一世11 分钟前
开源 Linux截图工具闪构(SnapForge)
linux·运维·ubuntu·开源·截图
iCxhust15 分钟前
先想好如何测试:让测试驱动你的程序设计
运维·服务器·软件工程·编程的艺术
北i27 分钟前
Dubbo 默认超时重试:把下游打雪崩的隐形放大器
开发语言·qt·dubbo
Philtell41 分钟前
突然连接不上内网服务器的问题
运维·服务器
朱包林1 小时前
iTerm2终端配置指南
linux·javascript·python·云原生·容器·kubernetes·云计算
祖力552 小时前
Linux系统移植、烧录与环境的搭建
linux·运维·服务器
skywalk81632 小时前
windows10 explorer占用太多内存问题解决
服务器·内存·windows10·explorer
张小姐的猫2 小时前
【Linux】网络编程 —— 多路转接:epoll
linux·运维·网络
宋明河3 小时前
五种 IO 模型与 select、poll、epoll 对比
linux
扶尔魔ocy3 小时前
【qt openGL入门笔记】OSG实现显示飞机模型飞行的点迹(二)
qt·opengl·osg