[Qt-interest] How to use QTime
Arnold Krille
arnold at arnoldarts.de
Thu Apr 16 15:34:37 CEST 2009
First: Thread-Hijacking is considered evil.
Clicking "Answer" and editing the subject is _not_ enough to start a new
thread.
On Thursday 16 April 2009 15:12:19 Parameshwari wrote:
> I have tried this code to generate a delay before
> displaying the Frame which is :
> QTime time = QTime::currentTime(); // get the current time
> QTime time2= QTime::currentTime().addSecs(5);
> this->showMaximized();
> while(time >= time2 )
> {
> time = QTime::currentTime();
> }
> this->close();
> But it is not working well. I am not sure whether i have done any mistake
> in the above code.
> In the file , The Window is maximized only. It' not even entering to the
> "while" loop i believe.
I don't really know what you want to achieve and you don't show enough code to
deduce that from the code, but:
A busy loop as you created it is _bad_, _old_ style. Don't use it! Actually
you keep your system busy in these five seconds and you don't let the event
loop run during that five seconds. So if you are waiting for an event to be
processed, that won't ever happen in that time.
QWidget::close() is actually a slot, so if you want your widget to be hidden
after five seconds of display, just do
QTimer::singleShot( 5000, this, SLOT(close()) );
inside your widgets constructor (or anywhere else).
Have fun,
Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090416/8921b5f9/attachment.bin
More information about the Qt-interest-old
mailing list