PDA

View Full Version : Problem with Splash Screen ?



vinod
22nd April 2006, 14:43
Hello,

Here is my code. I am trying to display the "Logo" image as a splash screen on top all of my windows. But when executing , the splash screen is displayed on bottom of the main widget. What is the reason ? How can I solve it ?


#include <qapplication.h>
#include "welform.h"
#include <qtimer.h>
#include <qpixmap.h>
#include <qsplashscreen.h>


int main( int argc, char ** argv )
{


QSplashScreen *splash=NULL;
QApplication a( argc, argv );
welForm *w;


QPixmap logo(QPixmap::fromMimeSource("Logo"));
splash=new QSplashScreen(logo,Qt::WStyle_StaysOnTop|Qt::WX11B ypassWM);
splash->show();
QTimer::singleShot(5*1000,splash,SLOT(close()));

w=new welForm(0,"welForm");
a.setMainWidget(w);
w->show();

//delete splash;
//a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
int rc=a.exec();

//splash->finish(w); this finish() also not work.... so I commented it.
if(splash)
delete splash;

return rc;
}


thanks in advance............

A S Vinod

wysota
22nd April 2006, 15:28
Try this:

QApplication app(argc, argv);
QSplashScreen *splashscreen = new QSplashScreen(QPixmap::fromMimeSource("Logo"), Qt::WDestructiveClose|Qt::WStyle_StaysOnTop); // no need for other flags
splashscreen->show();
app.processEvents(); // this should make the splash appear
welForm *w = new welForm(0,"welForm");
app.setMainWidget(w);
w->show();
QTimer::singleShot(5000,splashscreen,SLOT(close()) ); // timer needs the event queue
return app.exec();

vinod
24th April 2006, 07:14
Hello,

I had tried your code. But the result was same. The splash screen always appeared below to the main window.


So what will be he exact problem....


Vinod

wysota
24th April 2006, 09:08
Did you pass any window flags to the main window?

vinod
24th April 2006, 10:09
No , I didn't pass any arguments to main window...

But , now I solve the problem.

By just calling the finish(mainWindow) function of SplashScreen class before calling show(mainWindow).

Here is the working code :-


int main( int argc, char ** argv )
{

QApplication a( argc, argv );


QSplashScreen *splash=new
QSplashScreen(QPixmap::fromMimeSource("Logo"),Qt::WDestructiveClose|Qt::WStyle_StaysOnTop);
splash->show();
a.processEvents();
welForm *w=new welForm(0,"welForm");
a.setMainWidget(w);
splash->finish(w);
w->show();

QTimer::singleShot(10000,splash,SLOT(close()));
return a.exec();
}



Thank You...

yabadabadoo
7th March 2007, 07:51
hello...
i am trying to display a splash screen before my application starts. But it is not displaying SplashScreen. given below is my code.


#include <QApplication>

#include "client.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPixmap pixmap("redcross.png");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->show();
app.processEvents();
splash->showMessage("Loaded modules");

client client;//inherited from QDialog
splash->finish(&client);
client.show();

QTimer::singleShot(5000,splash,SLOT(close())); // timer needs the event queue

return app.exec();
}

thanx

wysota
7th March 2007, 09:51
I tested the code and it worked for me. Maybe the problem is that you use a relative path to the redcross.png image? If QSplashScreen can't find it, it won't be displayed.

yabadabadoo
7th March 2007, 09:57
yes.... that was the problem... thank you very much..

Prashant Kumar
19th January 2019, 17:51
can i use finish before calling show() on the mainwindow?

anda_skoa
26th January 2019, 09:13
can i use finish before calling show() on the mainwindow?

That is what the code in post #6 does, isn't it?.

Cheers,
_