PDA

View Full Version : splash screen problem



wizarda
14th January 2011, 05:52
Hi All,

I have created an application with a splash screen as it should be. The problem is that whenever I tap on the splash screen on my device (tested on N8 and E7), the application disappears and the background i.e. the phone menu is displayed. The application still runs in the background.
This application makes use of the internet and so it does its initial network lookup while the splash screen is on.

This issue does not occur with other applications which does not deal with initial network lookup.


The code for splash screen is as follows:


QPixmap splashPix(":/Images/splash_new.png");

QSplashScreen *splash = new QSplashScreen;

splash->setPixmap(splashPix);
splash->showFullScreen();

splash->raise();

Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
splash->showMessage(QObject::tr("Checking connectivity"),
Qt::AlignJustify, Qt::white);
Utils::sleep(1);
splash->showMessage(QObject::tr("Checking connectivity."),
Qt::AlignJustify, Qt::white);
Utils::sleep(1);
splash->showMessage(QObject::tr("Checking connectivity.."),
Qt::AlignJustify, Qt::white);

Utils::sleep(1);
splash->showMessage(QObject::tr("Checking connectivity..."),
Qt::AlignJustify, Qt::white);
splash->clearMessage();

net = isConnectedToNetwork(); // connection status call

if(net)
{
//Found an interface. Show status & proceed normally.
splash->showMessage(QObject::tr("Connection Found !!"),
Qt::AlignJustify, Qt::green);
qWarning("Connection found....");
Utils::sleep(2);
splash->showMessage(QObject::tr("Launching application"),
Qt::AlignJustify, Qt::green);
Utils::sleep(1);
splash->showMessage(QObject::tr("Launching application."),
Qt::AlignJustify, Qt::green);
Utils::sleep(1);
splash->showMessage(QObject::tr("Launching application.."),
Qt::AlignJustify, Qt::green);
Utils::sleep(1);
splash->showMessage(QObject::tr("Launching application..."),
Qt::AlignJustify, Qt::green);
Utils::sleep(1);
}
else
{
qWarning("Comes here");
splash->showMessage(QObject::tr("No Internet Connection !!\nPlease check the network settings.\nTrackIt will now exit..."),
Qt::AlignJustify, Qt::red);
Utils::sleep(5);

return -1;
}

Utils::sleep(5);

splash->clearMessage();
splash->finish(w);

w->showFullScreen();
delete splash;
splash = NULL;

Can anyone please help me with this issue?

Thanks and Regards.

wysota
14th January 2011, 12:12
What's the point of using sleep()? This blocks your application.

squidge
14th January 2011, 12:50
and is causing it to ignore messages from the OS, which might decide to remove you from the foreground as a result.

high_flyer
14th January 2011, 12:58
Maybe 'Utils' is a thread? then it is ok.

wysota
14th January 2011, 14:34
Maybe 'Utils' is a thread? then it is ok.

Then he's accessing widgets from a non-gui thread. So it's still no ok.

high_flyer
14th January 2011, 14:37
Then he's accessing widgets from a non-gui thread. So it's still no ok.
how do you come to that conclusion?
He could be very well in the Gui thread calling the non gui thread's sleep... (provided if overriden it to be public)
Or am I missing something?

To original poster:
You should explain a bit what you are doing, we can't just guess!

squidge
14th January 2011, 17:36
Could be, but I don't see why you'd call a sleep function on a different thread. Surely the point of the call is to delay the execution of the current thread so that the splash screen stays up longer, and if he's doing that, he can't be processing messages too.

wysota
14th January 2011, 19:10
how do you come to that conclusion?
He could be very well in the Gui thread calling the non gui thread's sleep... (provided if overriden it to be public)
Or am I missing something?
Several reasons. First of all I don't think you can put thread A to sleep from thread B. Second of all Utils::sleep() is a static call so unless Utils is a singleton class, it is likely that its behaviour is similar to QThread::sleep() which puts the current thread to sleep. Furthermore if it was the case that this call puts another thread to sleep then calling sleep() several times in a row wouldn't make any sense as the thread would already be sleeping after the first call.

high_flyer
14th January 2011, 21:25
First of all I don't think you can put thread A to sleep from thread B.
You could if you exposed sleep() and internally make the thead call its own sleep. (I wouldn't, you niether, but who knows? I have seen stranger things!)

Second of all Utils::sleep() is a static call so unless Utils is a singleton class, it is likely that its behaviour is similar to QThread::sleep() which puts the current thread to sleep.
That is a good point, which wraps it for me.
If Utils is a mother class, than he is putting him self to sleep.
If not, then its something like what I just wrote above, which is probably even worse.

Furthermore if it was the case that this call puts another thread to sleep then calling sleep() several times in a row wouldn't make any sense as the thread would already be sleeping after the first call.
Ah... how many times have we seen here stuff that doesn't make any sense? ;)

wysota
15th January 2011, 02:05
You could if you exposed sleep() and internally make the thead call its own sleep. (I wouldn't, you niether, but who knows? I have seen stranger things!)
You mean like "schedule a sleep"? Maybe... But I don't think that's the case here ;)


Ah... how many times have we seen here stuff that doesn't make any sense? ;)
I tend to assume that something someone did does make some sense until I have enough evidence or intuition to say otherwise.

Anyway, the solution is to use a timer instead of the sleep calls. And signals and slots, of course.