• 7797阅读
  • 10回复

Screen Splash 问题 [复制链接]

上一主题 下一主题
离线bombfans
 
只看楼主 倒序阅读 楼主  发表于: 2008-05-10
— 本帖被 XChinux 执行加亮操作(2008-05-10) —
在 Qt 3.2.1 平台上想写一个 Screen Splash,但是定时器部分编写的有问题,程序每次执行,Screen Splash 很快就结束了,完全没有达到应有的效果。

  1. #include <qapplication.h>
  2. #include <qlabel.h>
  3. #include <qsplashscreen.h>
  4. #include <qpushbutton.h>
  5. #include <qwidget.h>
  6. #include <qpaintdevice.h>
  7. #include <qtimer.h>
  8. int main(int argc,char *argv[])
  9. {
  10.     QApplication app(argc,argv);
  11.     QPushButton *button = new QPushButton("Quit",0);
  12.     QObject::connect(button,SIGNAL(clicked()),&app,SLOT(quit()));
  13.     QSplashScreen *splash = new QSplashScreen(QPixmap("splash.png"));
  14.     splash->message(QObject::tr("Test SplashScreen..."),Qt::AlignRight | Qt::AlignTop,Qt::white);
  15.     splash->show();
  16.     //有问题的定时器
  17.     //QTimer *timer;
  18.     //QObject::connect(timer,SIGNAL(timeout()),button,SLOT(show()));
  19.     //QObject::connect(timer,SIGNAL(timeout()),splash,SLOT(accept()));
  20.     //timer->start(100000000000000000);
  21.    
  22.     app.setMainWidget(button);
  23.     button->show();
  24.     splash->finish(button);
  25.     delete splash;
  26.    
  27.     return app.exec();
  28. }
离线wzc81614
只看该作者 1楼 发表于: 2008-05-10
离线bombfans
只看该作者 2楼 发表于: 2008-05-10
引用第1楼wzc81614于2008-05-10 17:18发表的  :
你可以看下这个帖子啊~
http://www.qtcn.org/bbs/read.php?tid=3758&keyword=Splash

这个帖子我看了,但是还是很迷惑不解,感觉我写的代码和这个帖子中的没什么大的出入啊。
离线XChinux

只看该作者 3楼 发表于: 2008-05-10
你的定时器是指针,没有new,所以不能->start()
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线bombfans
只看该作者 4楼 发表于: 2008-05-10
引用第3楼XChinux于2008-05-10 22:33发表的  :
你的定时器是指针,没有new,所以不能->start()


我将有问题的定时器代码做了如下的修改,但是在 nmake 的时候会报错,提示是这样的:

splash.cpp
.\splash.cpp(25) : error C2374: 'timer' : redefinition; multiple initialization
        .\splash.cpp(21) : see declaration of 'timer'
NMAKE : fatal error U1077: 'cl' : return code '0x2'
Stop.

  1.     //有问题的定时器
  2.     QTimer *timer = new QTimer( splash );
  3.     QObject::connect(timer,SIGNAL(timeout()),splash,SLOT(accept()));
  4.     timer->start(100000);
  5.    
  6.     QTimer *timer = new QTimer( button );
  7.     QObject::connect(timer,SIGNAL(timeout()),button,SLOT(show()));
  8.     timer->start(100000);
[ 此贴被bombfans在2008-05-10 22:58重新编辑 ]
离线bombfans
只看该作者 5楼 发表于: 2008-05-10
  按照之前的那篇帖子,修改为如下代码,Splash 还是一闪而过

    //有问题的定时器
    QTimer timer;
    //QTimer *timer = new QTimer( splash );
    QObject::connect(&timer,SIGNAL(timeout()),splash,SLOT(accept()));
    //timer.start(100000);
   
    //QTimer *timer = new QTimer( button );
    QObject::connect(&timer,SIGNAL(timeout()),button,SLOT(show()));
    timer.start(9000000000);
离线binghuiliang
只看该作者 6楼 发表于: 2008-05-12
QTimer::singleShot(10 * 1000, &splash, SLOT(hide()));

以后自己delete splash;
My blog:
http://blog.csdn.net/binghuiliang
离线bombfans
只看该作者 7楼 发表于: 2008-05-12
引用第6楼binghuiliang于2008-05-12 17:42发表的  :
QTimer::singleShot(10 * 1000, &splash, SLOT(hide()));
以后自己delete splash;

这段代码在 QT3 下无法通过编译吧?
离线turkeysy

只看该作者 8楼 发表于: 2008-05-13
问题太多,你的代码有太多的问题.
离线bombfans
只看该作者 9楼 发表于: 2008-05-13
引用第8楼turkeysy于2008-05-13 18:30发表的  :
问题太多,你的代码有太多的问题.

可否明示?
离线lala08
只看该作者 10楼 发表于: 2009-06-11
QApplication app(argc,argv);
QPushButton *button = new QPushButton("Quit",0);
QObject::connect(button,SIGNAL(clicked()),&app,SLOT(quit()));
QSplashScreen *splash = new QSplashScreen(QPixmap("splash.png"));
splash->message(QObject::tr("Test SplashScreen..."),Qt::AlignRight | Qt::AlignTop,Qt::white);

splash->show();

//有问题的定时器
//QTimer *timer;
//QObject::connect(timer,SIGNAL(timeout()),button,SLOT(show()));
//QObject::connect(timer,SIGNAL(timeout()),splash,SLOT(accept()));
//timer->start(100000000000000000);


app.setMainWidget(button);
button->show();
splash->finish(button);    这两句 在 主部件显示之后 就关闭splash 销毁 当然就看不见啦,注释掉这两句看看
delete splash;
快速回复
限100 字节
 
上一个 下一个