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();
}
相关推荐
奥修的灵魂1 分钟前
QT进阶之路:带命名空间的自定义控件在Qt设计器与qss中的使用技巧
qt·命名空间
weixin_461259411 小时前
[C]C语言日志系统宏技巧解析
java·服务器·c语言
m0_637146931 小时前
C语言基础面试问答
运维·服务器
t198751281 小时前
Linux 上的 Tomcat 端口占用排查
linux·tomcat·firefox
小狗爱吃黄桃罐头1 小时前
正点原子[第三期]Arm(iMX6U)Linux移植学习笔记-12.1 Linux内核启动流程简介
linux·arm开发·学习
Clownseven2 小时前
SSH/RDP无法远程连接?腾讯云CVM及通用服务器连接失败原因与超全排查指南
服务器·ssh·腾讯云
ricky_fan2 小时前
window下配置ssh免密登录服务器
运维·服务器·ssh
地衣君2 小时前
Ubuntu 配置使用 zsh + 插件配置 + oh-my-zsh 美化过程
linux·运维·ubuntu
2401_858286112 小时前
OS11.【Linux】vim文本编辑器
linux·运维·服务器·编辑器·vim
朱包林2 小时前
day27-shell编程(自动化)
linux·运维·服务器·网络·shell脚本