PDA

View Full Version : SplashScreen isn't displayed



Salazaar
26th June 2007, 17:26
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:

#include <QApplication>
#include <QPlastiqueStyle>
#include <QSplashScreen>
#include <QTimer>
#include "maker.h"
#include "about.h"

int main(int argc, char *argv[])
{
QApplication::setStyle ( new QPlastiqueStyle() );
QApplication app(argc, argv);
QPixmap pixmap(":new/prefix1/poker.png");
QSplashScreen splash(pixmap);


QTimer splashTimer;

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

jpn
26th June 2007, 17:43
Are you sure it doesn't show up? Something similar seems to show up for me. What if you make it on top:

QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);

Btw, there is a more convenient way for setting up a single shot timer:

QTimer::singleShot(4000, &splash, SLOT(close()));

Salazaar
26th June 2007, 18:04
Yes, I'm sure. I tried your code - without effect

jpn
26th June 2007, 18:23
In that case the problem must lie within the pixmap. Assure that the pixmap is not null, eg. QPixmap::isNull() returns false.

Salazaar
26th June 2007, 18:56
In docs I have short definition. How to use
bool QPixmap::isNull () const
Regards

jpn
26th June 2007, 19:55
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.

Salazaar
26th June 2007, 20:06
So I have to do something like this:

pixmap->isNull();
Yes?

jpn
26th June 2007, 20:28
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.

Salazaar
26th June 2007, 20:35
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

marcel
26th June 2007, 20:37
Sure it's something wrong with pixmap.
Make sure you added the qrc to the project file and that you rebuild the project.

Regards

fullmetalcoder
26th June 2007, 20:37
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...

marcel
26th June 2007, 20:40
You have in your code timeOut not timeout.
I'm sure console said the same.

Regards

jpn
26th June 2007, 20:45
Call QApplication::processEvents() after the splash.show()... and read the docs next time :p ...
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.

jpn
26th June 2007, 20:48
This seems to be a double thread (http://www.qtcentre.org/forum/f-newbie-4/t-splash-screen-page2-7376.html). Please don't start new threads on exactly the same subject.

marcel
26th June 2007, 20:50
This seems to be a double thread (http://www.qtcentre.org/forum/f-newbie-4/t-splash-screen-page2-7376.html). 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:


QPixmap pix = QPixmap( "c:\\image.png");


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

fullmetalcoder
26th June 2007, 20:50
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...

marcel
26th June 2007, 20:55
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.

Salazaar
26th June 2007, 21:33
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...

jpn
27th June 2007, 05:17
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 (http://doc.trolltech.com/4.3/debug.html).

Salazaar
27th June 2007, 17:07
D' you mean to use qDebug to see if pixmap.isNull() ?

jpn
27th June 2007, 17:50
D' you mean to use qDebug to see if pixmap.isNull() ?
In this case, yes. The list of possible use cases is endless, though.

Salazaar
27th June 2007, 18:51
I added line

qDebug() << "Is pixmap null:" << pixmap.isNull();
and reached in console:
QObject::connect: No such signal QTimer::timeout()
Is pixmap null: true
So there's a problem with loading image.

jpn
27th June 2007, 19:34
Could you paste the contents of .qrc file and the output of "tree -f" executed in the project directory from command line? About the signal, you have already been advised more than once how to fix that. ;)

Salazaar
27th June 2007, 20:42
Sure. Images.qrc:

<RCC>
<qresource prefix="/new/prefix1" >
<file>File.jpg</file>
<file>Poker.JPG</file>
<file>Poker.PNG</file>
<file>Tools.jpg</file>
<file>about.jpg</file>
<file>copy.jpg</file>
<file>cut.jpg</file>
<file>delete.jpg</file>
<file>delfile.jpg</file>
<file>exit.jpg</file>
<file>favicon.ico</file>
<file>find.jpg</file>
<file>font.jpg</file>
<file>help.jpg</file>
<file>mainlogo.jpg</file>
<file>new.jpg</file>
<file>paste.jpg</file>
<file>print.jpg</file>
<file>save.jpg</file>
<file>settings.jpg</file>
<file>sort.jpg</file>
</qresource>
</RCC>

And If I try tree -f I reach that there's no such command

jpn
27th June 2007, 20:50
Sure. Images.qrc:
So shouldn't it be something like:

QPixmap pixmap(":/new/prefix1/Poker.PNG");


And If I try tree -f I reach that there's no such command
I guess you're running some else Windows than XP/2000 then?

Salazaar
27th June 2007, 21:04
No, I've got XP. I tried your code - with result. Thanks. Now I have to solve problem with the signal

jpn
27th June 2007, 21:14
No, I've got XP
Oh, and actually it should be "tree /f" not "tree -f". ;) The command (http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/tree.mspx?mfr=true) should definitely be available in XP.