[solved]shows splashscreen but does not show its message
-
i created a splashscreen for my application; however, it shows the splashscreen and then disappears but it does not show its message like loading modules and establish connections through the showMessage(). why?
attached is my code
@
#include <QtGui/QApplication>
#include "mobile.h"
#include <QSplashScreen>int main(int argc, char *argv[])
{
QApplication a(argc, argv);QPixmap pixmap(":/images/mobile.jpg"); QSplashScreen *splash = new QSplashScreen(pixmap); splash->show(); a.processEvents(); //Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop; splash->showMessage("Setting up the main window..."); //topRight, Qt::white);
a.processEvents();
splash->showMessage("Loading modules...");
//topRight, Qt::white);a.processEvents();
splash->showMessage("Establishing connections..."); //topRight, Qt::white);
a.processEvents();
mobile w; w.show(); splash->finish(&w); delete splash; return a.exec();
}
@[edit: Code highlighted / Denis Kormalev]
-
BTW, working sample:
But, i used QScoperPointer. You can replace it to standart pointer or non-pointer class instance.
@QApplication app(argc, argv);
QScopedPointer<QSplashScreen> splash(new QSplashScreen(QPixmap(":/splash"))); splash->show(); splash->showMessage(QSplashScreen::tr("Loading..."), Qt::AlignBottom | Qt::AlignHCenter, Qt::black); app.processEvents();
// some code
splash->showMessage(QSplashScreen::tr("Settings Manager: loading saved settings"), Qt::AlignBottom | Qt::AlignHCenter, Qt::black); app.processEvents();
// loading settings
splash->showMessage(QSplashScreen::tr("Plugin Manager: loading plugins"), Qt::AlignBottom | Qt::AlignHCenter, Qt::black); app.processEvents();
// loading plugins
MainWindow w; w.setWindowTitle(app.applicationName()); w.showMaximized(); splash->finish(&w); int rslt = app.exec(); @
-
Hi,
I took the code and added a sleep, as the comments for do some stuff will not take time :-)
This code shows the texts:
@/**- this class is used to call sleep, as msleep is a protected function of QThread
/
class CxTestSleepThread : public QThread
{
public:
/*- this method is used to call sleep, as msleep is a protected function of
- QThread
- @param nMSecs milliseconds to sleep
*/
static void mySleep(int nMSecs)
{
msleep(nMSecs);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);QScopedPointer<QSplashScreen> splash(new QSplashScreen(QPixmap(":/splash"))); splash->show(); splash->showMessage(QSplashScreen::tr("Loading..."), Qt::AlignBottom | Qt::AlignHCenter, Qt::white); app.processEvents(); CxTestSleepThread::mySleep(500); // some code splash->showMessage(QSplashScreen::tr("Settings Manager: loading saved settings"), Qt::AlignBottom | Qt::AlignHCenter, Qt::white); app.processEvents(); CxTestSleepThread::mySleep(500); // loading settings splash->showMessage(QSplashScreen::tr("Plugin Manager: loading plugins"), Qt::AlignBottom | Qt::AlignHCenter, Qt::white); app.processEvents(); CxTestSleepThread::mySleep(500); // loading plugins MainWindow w; w.setWindowTitle(app.applicationName()); w.showMaximized(); splash->finish(&w); return app.exec();
}
@ - this class is used to call sleep, as msleep is a protected function of QThread
-
Maybe you are just showing black text on a black splashscreen?