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();
}
相关推荐
Chirp11 小时前
Windows下借助wsl2读取ext4格式磁盘
linux·windows
1892280486111 小时前
NY386固态MT29F32T08GWLBHD6-T:B
大数据·服务器·人工智能·科技·缓存
IMPYLH11 小时前
Linux 的 whoami 命令
linux·运维·服务器·bash
头歌实践平台11 小时前
头歌静态路由与默认静态路由
运维·服务器·网络
NashSKY11 小时前
RK3588 Linux SDK 编译、烧录与 MIPI 屏配置流程
linux·rk3588
宋浮檀s12 小时前
DVWA通关教程2
运维·服务器·前端·javascript
专注VB编程开发20年12 小时前
Python 的 C 扩展,本质上就是“去中心化的 COM”
java·服务器·开发语言·ide·python
JAVA社区12 小时前
Java进阶全套教程(七)—— Redis超详细实战详解
java·linux·开发语言·redis·面试·职场和发展
UrSpecial12 小时前
从零实现 Reactor + ThreadPool TCP 服务器
服务器·网络编程·reactor·tcp
2501_9127840812 小时前
Taocarts全链路反向海淘系统实战拆解:一个人+一台服务器,如何做到日处理200单?
运维·服务器·跨境电商·taocarts