我的应用程序是两个页面,第一页面有pushButton1,按下后显示第二个页面,用QwidgetStack 来实现,但在raiseWidget(1)时出错,请问为什莫?
以下是我的源程序
#ifndef FORM1_H
#define FORM1_H
#include <qvariant.h>
#include <qdialog.h>
class QVBoxLayout;
class QHBoxLayout;
class QGridLayout;
class QLabel;
class QPushButton;
class QWidget;
class QWidgetStack;
class Form1 : public QDialog
{
Q_OBJECT
public:
Form1( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 );
~Form1();
QWidgetStack* widgetStack1;
QWidget* page;
QPushButton* pushButton1;
QWidget* page_2;
QPushButton* pushButton2;
QPushButton* pushButton2_8;
QPushButton* pushButton2_7;
QPushButton* pushButton2_6;
QPushButton* pushButton2_5;
QPushButton* pushButton2_4;
QPushButton* pushButton2_3;
QPushButton* pushButton10;
QLabel* pixmapLabel1;
// connect( pushButton1, SIGNAL( clicked() ), widgetStack1, SLOT( raiseWidget( 1 ) ) );
//显示第二页
public slots:
void next();
protected:
protected slots:
virtual void languageChange();
};
#endif // FORM1_H
#include "form1.h"
#include <qvariant.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qwidget.h>
#include <qwidgetstack.h>
#include <qlayout.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
/*
* Constructs a Form1 as a child of 'parent', with the
* name 'name' and widget flags set to 'f'.
*
* The dialog will by default be modeless, unless you set 'modal' to
* TRUE to construct a modal dialog.
*/
Form1::Form1( QWidget* parent, const char* name, bool modal, WFlags fl )
: QDialog( parent, name, modal, fl )
{
if ( !name )
setName( "Form1" );
widgetStack1 = new QWidgetStack( this, "widgetStack1" );
widgetStack1->setGeometry( QRect( 0, 0, 600, 470 ) );
//页面一
page = new QWidget( widgetStack1, "page" );
pushButton1 = new QPushButton( page, "pushButton1" );
pushButton1->setGeometry( QRect( 90, 110, 421, 181 ) );
widgetStack1->addWidget( page, 0 );
//页面二
page_2 = new QWidget( widgetStack1, "page_2" );
pushButton2 = new QPushButton( page_2, "pushButton2" );
pushButton2->setGeometry( QRect( 50, 50, 81, 31 ) );
pushButton2_8 = new QPushButton( page_2, "pushButton2_8" );
pushButton2_8->setGeometry( QRect( 180, 50, 81, 31 ) );
pushButton2_7 = new QPushButton( page_2, "pushButton2_7" );
pushButton2_7->setGeometry( QRect( 310, 50, 81, 31 ) );
pushButton2_6 = new QPushButton( page_2, "pushButton2_6" );
pushButton2_6->setGeometry( QRect( 430, 50, 81, 31 ) );
pushButton2_5 = new QPushButton( page_2, "pushButton2_5" );
pushButton2_5->setGeometry( QRect( 90, 140, 81, 31 ) );
pushButton2_4 = new QPushButton( page_2, "pushButton2_4" );
pushButton2_4->setGeometry( QRect( 240, 140, 81, 31 ) );
pushButton2_3 = new QPushButton( page_2, "pushButton2_3" );
pushButton2_3->setGeometry( QRect( 380, 140, 81, 31 ) );
pushButton10 = new QPushButton( page_2, "pushButton10" );
pushButton10->setGeometry( QRect( 40, 380, 141, 41 ) );
pixmapLabel1 = new QLabel( page_2, "pixmapLabel1" );
pixmapLabel1->setGeometry( QRect( 400, 360, 131, 41 ) );
pixmapLabel1->setPixmap( QPixmap::fromMimeSource( "logo.png" ) );
pixmapLabel1->setScaledContents( TRUE );
widgetStack1->addWidget( page_2, 1 );
connect( pushButton1, SIGNAL( clicked() ), widgetStack1, SLOT( raiseWidget( 1 ) ) );
languageChange();
resize( QSize(602, 480).expandedTo(minimumSizeHint()) );
}
/*
* Destroys the object and frees any allocated resources
*/
Form1::~Form1()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Sets the strings of the subwidgets using the current
* language.
*/
void Form1::languageChange()
{
setCaption( tr( "Form1" ) );
pushButton1->setText( tr( "MULTIROOM SYSTEM\n"
"PUSH TO START" ) );
pushButton2->setText( tr( "SOURCE1" ) );
pushButton2_8->setText( tr( "SOURCE2" ) );
pushButton2_7->setText( tr( "SOURCE3" ) );
pushButton2_6->setText( tr( "SOURCE4" ) );
pushButton2_5->setText( tr( "SOURCE5" ) );
pushButton2_4->setText( tr( "SOURCE6" ) );
pushButton2_3->setText( tr( "SOURCE7" ) );
pushButton10->setText( tr( "INSTALLER" ) );
}
//这里使用raiseWidget
void Form1::next()
{
widgetStack1 -> raiseWidget( 1 );
}
#include <qapplication.h>
#include "form1.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
Form1 w;
w.show();
a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
return a.exec();
}