QSplashScreen Example not working
-
I am trying to implement a slash screen by editing my main file and adding some of the Qt4 example code.
this is what I have:
@
#include <QtGui/QApplication>
#include <QSplashScreen>
#include <QThread>
#include "mainwindow.h"int main(int argc, char *argv[])
{
// create application instance
QApplication a(argc, argv);// set up splash screen QPixmap pixmap("splash.jpg"); QSplashScreen *splash = new QSplashScreen(pixmap); splash->showMessage("Loading..."); // show splash screen splash->show(); // sleep for 3 seconds sleep(3); // show main window MainWindow w; w.show(); // remove splash screen splash->finish(&MainWindow); delete splash; return a.exec();
}
@Now for some reason I am getting and error on the splash->finish(&MainWindow); line stating its expecting a primary expression before the line. This confuses me because splash is the main pointer. This is directly from the Qt Documentation as well.
Any Ideas?
-
@
splash->finish(&w);
@MainWindow is a type, w a variable of that type. Please consider learning C++ basics before using Qt...
(Also: do not delete your splash screen before hiding it. Just create it on the stack, or find a way to deleteLater() it when it's closed).
-
Not related though, in the above code, sleep() is working ?
-
I haven't tried though, made a couple of small changes. Might work.
@#include <QtGui/QApplication>
#include <QSplashScreen>
#include <QThread>
#include "mainwindow.h"class I : public QThread
{
public:
static void sleep(unsigned long secs) {
QThread::sleep(secs);
}
};int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap("splash.jpg");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->showMessage("Loading...");
splash->show();I::sleep(3); MainWindow w; w.show(); splash->finish(&w); return a.exec();
}@
-
-
[quote author="peppe" date="1313187434"]http://developer.qt.nokia.com/wiki/Threads_Events_QObjects#92dd35cc61ffc41d02defdcef071856d
Please.[/quote]
Thank you Peppe, But,am still curious, how would i use QTimer in the above lines of codes?
I failed to do :( -
In the above code, it won't help, as you wanted the sleep before the mainwindow pops up.
-
What about
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap("splash.jpg");
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->showMessage("Loading...");
splash->show();MainWindow w; splash->finish(&w); QTimer t; t.setInterval(3000); t.setSingleShot(true); connect(&t,SIGNAL(timeout()),&w,SLOT(show())); connect(&t,SINGAL(timeout()),splash,SLOT(close())); t.start(); return a.exec();
}
@
EDIT: Nevermind, I had a wrong conception of finish() worked. I updated the code. It should work now. -
bq. I updated the code. It should work now.
Thanks alot loladiro, will try with this.