zl2k
9th September 2008, 17:17
hi, there
By clicking a button, I want to do heavy calculation several times in a loop and don't want them block the performance of the GUI, here is what I did. Although it did not block the GUI, it block the loop. How can I do it correct?
Somewhere in the GUI I have
for (int i = 1; i < 10; i++){
cout<<"# "<<i<<endl;
TrashThread trash(this, i);
trash.start();
}
For the TrashThread class, I have
TrashThread::TrashThread(QObject *parent, int i) : QThread(parent)
{
cout<<"thread "<<i<<endl;
}
TrashThread::~TrashThread()
{
}
void TrashThread::run()
{
cout<<"sleep 5sec"<<endl;
sleep(5);
exec();
}
and here is the result
# 0
thread 0
sleep 5sec
//the loop never goes to 2nd iteration
Thanks for help.
zl2k
By clicking a button, I want to do heavy calculation several times in a loop and don't want them block the performance of the GUI, here is what I did. Although it did not block the GUI, it block the loop. How can I do it correct?
Somewhere in the GUI I have
for (int i = 1; i < 10; i++){
cout<<"# "<<i<<endl;
TrashThread trash(this, i);
trash.start();
}
For the TrashThread class, I have
TrashThread::TrashThread(QObject *parent, int i) : QThread(parent)
{
cout<<"thread "<<i<<endl;
}
TrashThread::~TrashThread()
{
}
void TrashThread::run()
{
cout<<"sleep 5sec"<<endl;
sleep(5);
exec();
}
and here is the result
# 0
thread 0
sleep 5sec
//the loop never goes to 2nd iteration
Thanks for help.
zl2k