求教编程高手教我如何用Qt实现两窗口切换,比如点击窗口A后,窗口B弹出,而窗口A自动关闭...
我是用的是Qt3.3.4+vc6.0,我们专业设的课程。能贴出代码最好了,我是个初学者,好多类都不知道什么功能,求高手详细点的回答,谢过了...
我是用的是Qt3.3.4+vc6.0,我们专业设的课程。能贴出代码最好了,我是个初学者,好多类都不知道什么功能,求高手详细点的回答,谢过了
展开
展开全部
//窗口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();
QObject::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();
QObject::connect(a,SIGNAL(showB(bool)),b,SLOT(showB(bool)));
a->show();
return x.exec();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询