说明:MainWindow,SplashWindow,QIdel都是自定义继承至QWidget的类,QPEApplication类和QApplication类类似,可等同看待。
class QIdel: public QWidget
{
public:
QIdel(QWidget* parent=0,const char* name=0,WFlags fl=0);
~QIdel();
void init(QPEApplication* application,MainWindow* main,SplashWindow* sp);
QPEApplication* app;
MainWindow* main;
SplashWindow* sp;
public slots:
void hide();
};
void QIdel::init(QPEApplication* application,MainWindow* main,SplashWindow* sp)
{
this->app=application;
this->main=main;
this->sp=sp;
}
QIdel::QIdel(QWidget* parent,const char* name,WFlags fl):QWidget(parent,name,fl)
{
}
QIdel::~QIdel()
{
}
//slots
void QIdel::hide()
{
sp->close();
app->setMainWidget(main);
}
int main(int argc, char** argv)
{
QPEApplication app(argc, argv);
MainWindow* mw=new MainWindow();
SplashWindow* sp=new SplashWindow();
sp->show();
QIdel* id=new QIdel();
id->init(&app,mw,sp);
QTimer::singleShot(4*1000,id,SLOT(hide()));
//app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}
程序运行结果:显示sp对象4秒,之后消失,当我要的mw对象却没有显示出来,好似乎没有执行void hide()函数里的语句:app->setMainWidget(main);,程序就此结束,还敬请总版主协助查看一下,不胜感谢!