SplashScreen isn't displayed
Hi. I've got a problem. I've created splashscreen, timer to it, but have a problem. Splashscreen is not displayed when application starts. Here's the code from main.cpp:
Code:
#include <QApplication>
#include <QPlastiqueStyle>
#include <QSplashScreen>
#include <QTimer>
#include "maker.h"
#include "about.h"
int main(int argc, char *argv[])
{
QPixmap pixmap
(":new/prefix1/poker.png");
splashTimer.setSingleShot( true );
splashTimer.setInterval( 4000 ); //4 seconds
QObject::connect( &splashTimer,
SIGNAL( timeOut
() ),
&splash,
SLOT( close
()) );
splashTimer.start();
splash.show();
MainWindow MainWindow;
MainWindow.show();
return app.exec();
}
Of course I have this image in my resource file. What's wrong? Regards
Re: SplashScreen isn't displayed
Are you sure it doesn't show up? Something similar seems to show up for me. What if you make it on top:
Btw, there is a more convenient way for setting up a single shot timer:
Code:
QTimer::singleShot(4000,
&splash,
SLOT(close
()));
Re: SplashScreen isn't displayed
Yes, I'm sure. I tried your code - without effect
Re: SplashScreen isn't displayed
In that case the problem must lie within the pixmap. Assure that the pixmap is not null, eg. QPixmap::isNull() returns false.
Re: SplashScreen isn't displayed
In docs I have short definition. How to use
bool QPixmap::isNull () const
Regards
Re: SplashScreen isn't displayed
Quote:
Originally Posted by
Salazaar
In docs I have short definition. How to use
bool QPixmap::isNull () const
It's a member function of QPixmap. Call it the same way than you call QWidget::show() or QCoreApplication::exec(). The returned value indicates whether the pixmap has content or not. Showing a splash screen with null pixmap makes nothing to appear.
Re: SplashScreen isn't displayed
So I have to do something like this:
Yes?
Re: SplashScreen isn't displayed
Did you try to compile it? Variable pixmap is not a pointer so it would be pixmap.isNull(). Check the return value with a debugger or print it to debug output.
Re: SplashScreen isn't displayed
I placed this in main.cpp, and reached in console window:
QObject::connect: No such signal QTimer::timeout()
But even if there's no timeout() signal, it should show splash
Re: SplashScreen isn't displayed
Sure it's something wrong with pixmap.
Make sure you added the qrc to the project file and that you rebuild the project.
Regards
Re: SplashScreen isn't displayed
Call QApplication::processEvents() after the splash.show()... and read the docs next time :p ... a QWidget can't appear before the application event loop starts running unless :
- It has an event loop of its own, just like QMessageBox
- You manually force events processing
If you want to display messages (or change the content of the splash in any way...) you'll have to call the same function after each change to allow propagation of show/hide/reisze/paint events...
Re: SplashScreen isn't displayed
You have in your code timeOut not timeout.
I'm sure console said the same.
Regards
Re: SplashScreen isn't displayed
Quote:
Originally Posted by
fullmetalcoder
Actually, processing pending events does not solve the problem. QCoreApplication::exec() is already called and the splash screen is shown by then, same time with the main window. It's just that the pixmap is not loaded correctly so no splash screen is shown either.
Re: SplashScreen isn't displayed
This seems to be a double thread. Please don't start new threads on exactly the same subject.
Re: SplashScreen isn't displayed
Quote:
Originally Posted by
jpn
This seems to be a
double thread. Please don't start new threads on exactly the same subject.
Yes, it seemed kind of familiar... The suggestions just came out, no thinking at all. :)
Anyway, Sal, loose the resource file and put the png somewhere accessible, like "c:\\image.png" ( this is to make sure you don't mess up the path ), and load the pixmap like this:
There is no room for mistakes here. If it still doesn't show, then try changing the window flags for the splash. But only if that doesn't work.
Regards
Re: SplashScreen isn't displayed
Quote:
Originally Posted by
jpn
t's just that the pixmap is not loaded correctly so no splash screen is shown either.
Good point! It might not be the problem here but AFAIK, by default, resources use UNIX-like path, i.e. there is a '/' at the begining...
Re: SplashScreen isn't displayed
Quote:
Originally Posted by
fullmetalcoder
Good point! It might not be the problem here but AFAIK, by default, resources use UNIX-like path, i.e. there is a '/' at the begining...
Yes, I guess this is it :).
Well, this and actually compiling the qrc.
Re: SplashScreen isn't displayed
This is it. Now splash is displayed. So I have a wrong adress of image in resource file. Of course I have resource file included in my .pro file. But what's the correct adress of this image...hmm...
Re: SplashScreen isn't displayed
Quote:
Originally Posted by
Salazaar
This is it. Now splash is displayed. So I have a wrong adress of image in resource file. Of course I have resource file included in my .pro file. But what's the correct adress of this image...hmm...
This is what I was trying to help you to realize yourself. It would be great help for you to learn, if not how to use debugger for now, but at least how to print informative messages to debug output.
Re: SplashScreen isn't displayed
D' you mean to use qDebug to see if pixmap.isNull() ?