PDA

View Full Version : problem with msleep



Reinexen
26th December 2007, 01:57
Hi,
I'm having a problem with msleep function void QThread::msleep ( unsigned long msecs )
I dont really know how to use it.
I have a class "Labirynt" and a function in it: void Generate();
Something like this:


void Labirynt::Generate()
{
for(int i=10; i<100; i++)
{
//mathematical calculations (these are changing variables which are used in
// Labirynt::paintEvent [this is why i use update();])
QThread::msleep(20);
update();
}
}

My Error:
c:/Qt/4.3.3/include/QtCore/../../src/corelib/thread/qthread.h:108: error: `static void QThread::msleep(long unsigned int)' is protected
labirynt.cpp:67: error: within this context

What should i do to make it work?
When i use sleep from standard library program hangs up.
When i use my own sleep function program hangs up.

jacek
26th December 2007, 02:07
Don't put your GUI thread into sleep, use QTimer instead.

Reinexen
27th December 2007, 14:14
Thanks.

This is what i did and it works :cool: with qmake 4.3:


void Labirynt::oncemore()
{
loop++;
Generate();
update();
}

void Labirynt::Generate()
{
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(oncemore()));

//mathematical calculations (these are changing variables which are used in
// Labirynt::paintEvent [this is why i use update();])

if(loop<120)
timer->singleShot(100, this, SLOT(oncemore()));

}

jacek
28th December 2007, 16:32
It would be better if you had only one timer.