标题:qt+vs2008小例子 窗口切换一种办法
只看楼主
lateraware
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2012-2-9
结帖率:66.67%
 问题点数:0 回复次数:0 
qt+vs2008小例子 窗口切换一种办法
/***************   window.h   ***********/
#ifndef _WINDOW_H
#define _WINDOW_H

#include <qwidget.h>

class QPushButton;

class MyWidget1:public QWidget
{
    Q_OBJECT
public:
    MyWidget1(QWidget *parent = 0, const char *name = 0);
private:
    QPushButton *close;
signals:
    void send1();
};

class MyWidget2:public QWidget
{
    Q_OBJECT
public:
    MyWidget2(QWidget *parent = 0, const char *name = 0);
private:
    QPushButton *back;
signals:
    void send2();
};

class MyWidget:public QWidget
{
public:
    MyWidget(QWidget *parent = 0, const char *name = 0);
private:
    MyWidget1 *w1;
    MyWidget2 *w2;
};

#endif
/*******************************************************/

/********************   window.cpp  ********************/
#include "window.h"
#include "window_moc.cpp"
#include <qpushbutton.h>

MyWidget1::MyWidget1(QWidget *parent, const char *name):QWidget(parent, name)
{
    close = new QPushButton(tr("close"), this);

    connect(close, SIGNAL(clicked()), this, SIGNAL(send1()));
    connect(close, SIGNAL(clicked()), this, SLOT(close()));
    show();
}

MyWidget2::MyWidget2(QWidget *parent, const char *name):QWidget(parent, name)
{
    back = new QPushButton(tr("back"), this);

    connect(back, SIGNAL(clicked()), this, SIGNAL(send2()));
    connect(back, SIGNAL(clicked()), this, SLOT(close()));
}

MyWidget::MyWidget(QWidget *parent, const char *name):QWidget(parent, name)
{
    w1 = new MyWidget1;
    w2 = new MyWidget2;
//emit(send1())
    connect(w1, SIGNAL(send1()), w2, SLOT(show()));
    connect(w2, SIGNAL(send2()), w1, SLOT(show()));
}
/****************************************************************/

/**************************   main.cpp   ************************/
#include "window.h"
#include <qapplication.h>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MyWidget w;
    w.show();
    return app.exec();
}
/****************************************************************/


/**********************  配置  **********************************/
附加包含目录:C:\Qt\4.7.4\include\Qt;C:\Qt\4.7.4\include\QtGui;C:\Qt\4.7.4\src\gui\kernel
附加依赖项:qtcore4.lib qtgui4.lib
右键window.h=》属性=》命令行:moc $(InputPath) -o $(InputDir)$(InputName)_moc.cpp 输出:$(InputName)_moc.cpp
配置环境变量:
选择工具->选项->项目和解决方案->VC++目录。
               (1)  选择“可执行文件”,在里面添加:C:\Qt4.7.4\bin;
               (2)  选择“包含文件”,在里面添加:C:\Qt4.7.4\include;   C:\Qt4.7.4\include\Qt;   
                      C:\Qt4.7.0\include\QtCore;   C:\Qt4.7.4\include\QtGui
               (3)  选择“库文件”,在里面添加:C:\Qt4.7.4\lib;
/******************************************************************/

搜索更多相关主题的帖子: class void private include public 
2012-03-06 13:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-362354-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.474251 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved