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 (int i = 1; i < 10; i++){
cout<<"# "<<i<<endl;
TrashThread trash(this, i);
trash.start();
}
To copy to clipboard, switch view to plain text mode
For the TrashThread class, I have
{
cout<<"thread "<<i<<endl;
}
TrashThread::~TrashThread()
{
}
void TrashThread::run()
{
cout<<"sleep 5sec"<<endl;
sleep(5);
exec();
}
TrashThread::TrashThread(QObject *parent, int i) : QThread(parent)
{
cout<<"thread "<<i<<endl;
}
TrashThread::~TrashThread()
{
}
void TrashThread::run()
{
cout<<"sleep 5sec"<<endl;
sleep(5);
exec();
}
To copy to clipboard, switch view to plain text mode
and here is the result
# 0
thread 0
sleep 5sec
//the loop never goes to 2nd iteration
# 0
thread 0
sleep 5sec
//the loop never goes to 2nd iteration
To copy to clipboard, switch view to plain text mode
Thanks for help.
zl2k
Bookmarks