PDA

View Full Version : display QSplashScreen



HelloDan
8th February 2009, 05:50
At the startup of a Qt program, I want to display a QSplashScreen. Maybe it's too fast to get the image. But how can i make the image to last for 2 seconds.
I'm a greenhand, Thanks!

janus
8th February 2009, 09:13
Hi,
maybe you can connect a QTimer to a splashscreen slot. But in general you should be happy that your app starts so fast ;)

HelloDan
8th February 2009, 11:29
Hi,
maybe you can connect a QTimer to a splashscreen slot. But in general you should be happy that your app starts so fast ;)

I had looked up the documentation, but i failed to make it. Can you give me an example? Thanks

GioFX
8th February 2009, 21:41
int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QSplashScreen *splash = new QSplashScreen;
splash->setPixmap(QPixmap(":/images/splash.png"));
splash->show();

MyApp mainwindow;

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainwindow, SLOT(show()));

return app.exec();
}

HelloDan
9th February 2009, 14:27
Thanks for your reply.

But the main problem is that I can't see the image. Even I can make it to delay 2s, but the startup picture didn't turn up.

What's the problem? Can anyone help? Thanks

janus
9th February 2009, 14:40
Hi,

hard to guess without code ;)

GioFX
9th February 2009, 14:47
Thanks for your reply.

But the main problem is that I can't see the image. Even I can make it to delay 2s, but the startup picture didn't turn up.

What's the problem? Can anyone help? Thanks

did you set up a qrc file?

HelloDan
10th February 2009, 07:25
did you set up a qrc file?

Thanks for your advice.



#include <QApplication>
#include <QSplashScreen>
//#include <QThread>
//#include<QTimer>
#include<ctime>
#include "mainwindow.h"
/*
class SleeperThread : public QThread
{
public:
static void msleep(unsigned long msecs)
{
QThread::msleep(msecs);
}
};
*/

int main(int argc, char *argv[])
{
QApplication app(argc, argv);


QSplashScreen *splash=new QSplashScreen;
splash->setPixmap(QPixmap(":/images/splash.png"));
splash->show();

//splash->showMessage( "Initializing..." );
// app.processEvents();
//......................
MainWindow mainWin;

splash->showMessage( "Creating Widgets Page..." );
app.processEvents();

splash->showMessage( "Creating Database Page..." );
app.processEvents();

splash->showMessage( "Creating Games Page..." );
app.processEvents();

// SleeperThread::msleep(2000);

time_t t;
t = time(NULL);


//QTimer::singleShot(2500, splash, SLOT(close()));
//QTimer::singleShot(2500, &mainWin, SLOT(show()));



mainWin.show();

while( difftime(time(NULL),t) < 5.0 ) { }


splash->finish(&mainWin);
delete splash;

return app.exec();
}



This time, I changed my code and alse set up my qrc file. But the program just show a left top rectangle area of the program instead of the image. How can i make image show?
I will appreciate any reply. Thanks

janus
10th February 2009, 20:05
Hi,

did you add qrc file to the project file and does it have the correct path prefix?

HelloDan
11th February 2009, 17:27
Hi,

did you add qrc file to the project file and does it have the correct path prefix?

Thanks! In fact I had done all the things. But I found that the following code did make shown the startup images. But the image under the program, So I can't see the startup image. Thanks





#include <QApplication>
#include<QTimer>
#include <QSplashScreen>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QSplashScreen *splash = new QSplashScreen;
splash->setPixmap(QPixmap(":/images/splash.png"));
splash->show();



MainWindow mainWin;

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainWin, SLOT(show()));


mainWin.show();
return app.exec();
}

aamer4yu
11th February 2009, 17:51
You shouldnt be calling mainWin.show() since it will show after timer times out.

Still you can have the following sequence too -

mainWin.show();
splash.show();
QTimer::singleShot(2500, splash, SLOT(close()));

Hope it works :)

talk2amulya
11th February 2009, 18:18
i dont think mainWin should be shown before the splashscreen..after all, the primary reason of using a splashscreen is to show smth until the main window will show..thus, just removing the mainWin.show should work..also u can have a bit of delay in closing the splash and showing the mainWin..so, if i were u, i'd write


MainWindow mainWin;

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2600, &mainWin, SLOT(show()));

jpn
11th February 2009, 19:12
By the way, QSplashScreen hides automatically when you click on it. There's no need to delay showing of the main window when the splash screen was clicked away, right?

HelloDan
12th February 2009, 04:16
By the way, QSplashScreen hides automatically when you click on it. There's no need to delay showing of the main window when the splash screen was clicked away, right?

Thanks. Indeed. I tried it

HelloDan
12th February 2009, 04:20
You shouldnt be calling mainWin.show() since it will show after timer times out.

Still you can have the following sequence too -

mainWin.show();
splash.show();
QTimer::singleShot(2500, splash, SLOT(close()));

Hope it works :)

Thanks. But I just want the splash to show up before the app

HelloDan
12th February 2009, 04:24
i dont think mainWin should be shown before the splashscreen..after all, the primary reason of using a splashscreen is to show smth until the main window will show..thus, just removing the mainWin.show should work..also u can have a bit of delay in closing the splash and showing the mainWin..so, if i were u, i'd write


MainWindow mainWin;

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2600, &mainWin, SLOT(show()));

Thanks!
But it doesn,t works. the main program will still cover the startup image.

It's that any methods?

aamer4yu
12th February 2009, 05:18
hanks. But I just want the splash to show up before the app
I said u need call mainWindow.show(); u were going to show main window after timer times out.
Also in above post, did u call splash.show() ?

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QSplashScreen *splash = new QSplashScreen;
splash->setPixmap(QPixmap(":/images/splash.png"));
splash->show();

MainWindow mainWin;

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainWin, SLOT(show()));

return app.exec();
}

talk2amulya
12th February 2009, 06:38
ok, this code is working


#include <QtGui/QApplication>
#include "qtnetwork.h"
#include<QTimer>
#include <QSplashScreen>
#include <QMainWindow>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QSplashScreen *splash = new QSplashScreen;
splash->setPixmap(QPixmap("C:\\Documents and Settings\\am002bh\\Desktop\\error-checkin.PNG"));
splash->show();

QMainWindow mainWin;

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainWin, SLOT(show()));

return a.exec();
}


i have used QMainWindow and instead of using a qrc, i have used a straight path..so either u have a problem with ur qrc or mainwindow itself

HelloDan
13th February 2009, 04:49
Thanks all of you.

I made a mistake. There are two winMain.show();

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainWin, SLOT(show()));


mainWin.show();

raedbenz
21st August 2010, 10:19
Thanks all of you.

I made a mistake. There are two winMain.show();

QTimer::singleShot(2500, splash, SLOT(close()));
QTimer::singleShot(2500, &mainWin, SLOT(show()));


mainWin.show();
could you please post the complete working code?
also r u working on on Which OS r u working?

Thanks