请教各位大神。 Qt 如何在打开子窗口后父窗口自动关闭。或者关闭子窗口的时候父窗口也同时关闭
我做了一个welcom的父窗口,然后有一个“进入”的butto,当点击button的时候,就进入到了client的子窗口。然后请问,如何在进入了子窗口后父窗口就随之关闭。...
我做了一个welcom的父窗口,然后有一个“进入”的butto,当点击button的时候,就进入到了client的子窗口。
然后请问,如何在进入了子窗口后父窗口就随之关闭。或者说关闭子窗口的时候,父窗口也一起关闭了。 展开
然后请问,如何在进入了子窗口后父窗口就随之关闭。或者说关闭子窗口的时候,父窗口也一起关闭了。 展开
推荐于2016-11-22 · 知道合伙人互联网行家
关注
展开全部
//窗口A
#ifndef A_H
#define A_H
#include <QWidget>
#include <QMouseEvent>
class A : public QWidget
{
Q_OBJECT
public:
explicit A(QWidget *parent = 0);
signals:
void showB(bool isShow);
protected:
void mousePressEvent(QMouseEvent *event);
public slots:
};
#endif // A_H
//A.cpp
#include "a.h"
A::A(QWidget *parent) :
QWidget(parent)
{
this->setWindowTitle("我是A");
}
void A::mousePressEvent(QMouseEvent *event){
if(event->button()==Qt::LeftButton){
emit showB(true);
this->deleteLater();
}
}
//窗口B
#ifndef B_H
#define B_H
#include <QWidget>龚缉夺垦懿旧额驯帆沫
class B : public QWidget
{
Q_OBJECT
public:
explicit B(QWidget *parent = 0);
signals:
public slots:
void showB(bool isShow);
};
//B.cpp
#include "b.h"
B::B(QWidget *parent) :
QWidget(parent)
{
this->setWindowTitle("我是B");
}
void B::showB(bool isShow){
if(isShow)
this->show();
else
this->deleteLater();
}
//main.cpp
#include <QtGui/QApplication>
#include <QTextCodec>
#include "a.h"
#include "b.h"
int main(int argc, char *argv[])
{
QApplication x(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
B *b=new B();
A *a=new A();
QObjec t::connect(a,SIGNAL(showB(bool)),b,SLOT(showB(bool)));
a->show();
return x.exec();
}
#ifndef A_H
#define A_H
#include <QWidget>
#include <QMouseEvent>
class A : public QWidget
{
Q_OBJECT
public:
explicit A(QWidget *parent = 0);
signals:
void showB(bool isShow);
protected:
void mousePressEvent(QMouseEvent *event);
public slots:
};
#endif // A_H
//A.cpp
#include "a.h"
A::A(QWidget *parent) :
QWidget(parent)
{
this->setWindowTitle("我是A");
}
void A::mousePressEvent(QMouseEvent *event){
if(event->button()==Qt::LeftButton){
emit showB(true);
this->deleteLater();
}
}
//窗口B
#ifndef B_H
#define B_H
#include <QWidget>龚缉夺垦懿旧额驯帆沫
class B : public QWidget
{
Q_OBJECT
public:
explicit B(QWidget *parent = 0);
signals:
public slots:
void showB(bool isShow);
};
//B.cpp
#include "b.h"
B::B(QWidget *parent) :
QWidget(parent)
{
this->setWindowTitle("我是B");
}
void B::showB(bool isShow){
if(isShow)
this->show();
else
this->deleteLater();
}
//main.cpp
#include <QtGui/QApplication>
#include <QTextCodec>
#include "a.h"
#include "b.h"
int main(int argc, char *argv[])
{
QApplication x(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
B *b=new B();
A *a=new A();
QObjec t::connect(a,SIGNAL(showB(bool)),b,SLOT(showB(bool)));
a->show();
return x.exec();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询