Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, January 2007
Make a Qt application wait (sleep)


Message 1 in thread

Is there a way to put a wait or a sleep in the middle of a function,
without creating a QThread or deriving a class from QThread?
I simply want the app to wait for 500 ms.  No processing
or message handling needs to be done during that interval

void myfun()
{
    foo();
    sleep(500);  // wait for relay to close
    bar();    // continue processing
}

Thanks!


--
 [ signature omitted ] 

Message 2 in thread

"John Smith" <invalid@xxxxxxxxxxx> wrote in message 
news:enmfqs$clo$1@xxxxxxxxxxxxxxxxxxxxx
> Is there a way to put a wait or a sleep in the middle of a function,
> without creating a QThread or deriving a class from QThread?
> I simply want the app to wait for 500 ms.  No processing
> or message handling needs to be done during that interval
>
> void myfun()
> {
>    foo();
>    sleep(500);  // wait for relay to close
>    bar();    // continue processing
> }
>
> Thanks!

Now see the similar question and answers posted earlier.



--
 [ signature omitted ] 

Message 3 in thread

> From: John Smith [mailto:invalid@xxxxxxxxxxx]
> Sent: Friday, January 05, 2007 1:27 PM
> To: qt-interest@xxxxxxxxxxxxx
> Subject: Make a Qt application wait (sleep)
> 
> Is there a way to put a wait or a sleep in the middle of a function,
> without creating a QThread or deriving a class from QThread?
> I simply want the app to wait for 500 ms.  No processing
> or message handling needs to be done during that interval
What about UI updates?

I create a sleep function that does updates using the following:

QTime dieTime = QTime::currentTime().addSecs(2);
while( QTime::currentTime() < dieTime )
	QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

Scott


> 
> void myfun()
> {
>     foo();
>     sleep(500);  // wait for relay to close
>     bar();    // continue processing
> }
> 
> Thanks!
> 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ] 

Message 4 in thread

This might work great, and it might crash your application. If you are
currently processing certain events (window activate or close, for instance)
you can get Qt in an unstable state. (I know, I've done it.)

You probably want to exclude user events in this case as well. Regardless,
test this and try clicking on window widgets while it is in this loop.

Keith

On 01-05-2007 1:38 PM, "Scott Aron Bloom" wrote:

>> From: John Smith [mailto:invalid@xxxxxxxxxxx]
>> Sent: Friday, January 05, 2007 1:27 PM
>> To: qt-interest@xxxxxxxxxxxxx
>> Subject: Make a Qt application wait (sleep)
>> 
>> Is there a way to put a wait or a sleep in the middle of a function,
>> without creating a QThread or deriving a class from QThread?
>> I simply want the app to wait for 500 ms.  No processing
>> or message handling needs to be done during that interval
> What about UI updates?
> 
> I create a sleep function that does updates using the following:
> 
> QTime dieTime = QTime::currentTime().addSecs(2);
> while( QTime::currentTime() < dieTime )
> QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
> 
> Scott
> 
> 
>> 
>> void myfun()
>> {
>>     foo();
>>     sleep(500);  // wait for relay to close
>>     bar();    // continue processing
>> }
>> 
>> Thanks!


--
 [ signature omitted ] 

Message 5 in thread

I stripped code from my wrapper function... My function takes 2
parameters, and I should have been cleaner.

The first is the time to sleep, and the second if you want to ignore
user events or not.

But yes, your points are correct.

Scott

> -----Original Message-----
> From: Keith Esau [mailto:keith.esau@xxxxxxx]
> Sent: Friday, January 05, 2007 1:45 PM
> To: Qt Interest
> Subject: Re: Make a Qt application wait (sleep)
> 
> This might work great, and it might crash your application. If you are
> currently processing certain events (window activate or close, for
> instance)
> you can get Qt in an unstable state. (I know, I've done it.)
> 
> You probably want to exclude user events in this case as well.
Regardless,
> test this and try clicking on window widgets while it is in this loop.
> 
> Keith
> 
> On 01-05-2007 1:38 PM, "Scott Aron Bloom" wrote:
> 
> >> From: John Smith [mailto:invalid@xxxxxxxxxxx]
> >> Sent: Friday, January 05, 2007 1:27 PM
> >> To: qt-interest@xxxxxxxxxxxxx
> >> Subject: Make a Qt application wait (sleep)
> >>
> >> Is there a way to put a wait or a sleep in the middle of a
function,
> >> without creating a QThread or deriving a class from QThread?
> >> I simply want the app to wait for 500 ms.  No processing
> >> or message handling needs to be done during that interval
> > What about UI updates?
> >
> > I create a sleep function that does updates using the following:
> >
> > QTime dieTime = QTime::currentTime().addSecs(2);
> > while( QTime::currentTime() < dieTime )
> > QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
> >
> > Scott
> >
> >
> >>
> >> void myfun()
> >> {
> >>     foo();
> >>     sleep(500);  // wait for relay to close
> >>     bar();    // continue processing
> >> }
> >>
> >> Thanks!
> 
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/

--
 [ signature omitted ]