PDA

View Full Version : QSplashScreen question



graciano
12th July 2009, 23:39
Hi,
In the following code ...

#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPixmap pixmap("f0.png");
QSplashScreen splash(pixmap);
splash.show();
app.processEvents();
//...
QMainWindow window;
window.show();
splash.finish(&window);
return app.exec();

}
... isn't it expected a mouse click to close the splash screen?

Or does it mean that i can use the mouse click to close the splash before the QMainWindow finishes loading?

nish
13th July 2009, 02:59
can you rephrase your question? i cant understand what you want to ask.

aamer4yu
13th July 2009, 06:13
From your code, I guess the splash screen wont be shown.
Read QSplashScreen::finish. You are calling window.show() and setting finish on the window.
try showing the window from a timer... say after 2 seconds. and dont call show in the main function itself.

nish
13th July 2009, 07:00
From your code, I guess the splash screen wont be shown.
Read QSplashScreen::finish. You are calling window.show() and setting finish on the window.
try showing the window from a timer... say after 2 seconds. and dont call show in the main function itself.

but this is the correct way... Qt Assitant shows the same example

mcosta
13th July 2009, 08:53
This code close the QSplashScreen when the user clicks on it or when the mainwindow is ready to show

graciano
13th July 2009, 09:07
This was my interpretation also.
But by the way:

#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPixmap pixmap("f0.png");
QSplashScreen splash(pixmap);
splash.show();
//app.processEvents();
//...
QMainWindow window;
window.show();
//splash.finish(&window);
return app.exec();

}

Commented this 2 lines and both splash and main windows open at the same time. Click closes the splash.
Thought this was only possible if using app.processEventes(); !

nish
13th July 2009, 09:40
This was my interpretation also.
Thought this was only possible if using app.processEventes(); !
if you read the docs again.. it says that app.processEvents() is used because app.exe() is not called yet. When your mainwindow is shown, app.exe() is called so no need of processEvents().

graciano
14th July 2009, 13:39
And in this case:

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

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSplashScreen *splash = new QSplashScreen;
splash->setPixmap(QPixmap("f0.png"));
splash->show();
splash->showMessage(QObject::trUtf8("A preparar a janela principal ..."), Qt::AlignRight|Qt::AlignTop, Qt::black);
MainWindow w;
QTimer::singleShot(5000, splash, SLOT(close()));
QTimer::singleShot(5000, &w, SLOT(show()));
//delete splash;
return a.exec();
}

Obviously the commented line could not work ... but where to free the used memory by the splash screen?
Thanks