Thanks! The other thread told me enough to get it almost all set up. Basically its like this: (cond is a QWaitCondition, and mutex is a QMutex)
Main Thread:
Signals: getReady(int), insert(QString*, QString*, QString*)
Slots: updateTree(QTreeWidget*)
Worker Thread:
Signals: done(QTreeWidget*)
Slots: prepare(int), insertOne(QString*,QString*,QString*)
insertOne(...) sets the Worker Threads variables, and then if it isn't running starts it, otherwise it calls cond.wakeOne().
prepare(...) sets total.
So the sequence would be:
1) Main Thread -> getReady()
2) Worker Thread -> prepare()
3)
--- a lot of times
Main Thread ->insert()
Worker Thread -> insertOne()
---
4) Worker Thread -> done()
5) Main Thread -> updateTree()
and sudo code for Worker::run():
forever {
mutex->lock()
...
insert into tree
...
mutex->unlock()
if (numDone == total) {
emit done(treeWidget);
return;
}
mutex->.lock();
cond->wait(mutex);
mutex->unlock();
}
forever {
mutex->lock()
...
insert into tree
...
mutex->unlock()
if (numDone == total) {
emit done(treeWidget);
return;
}
mutex->.lock();
cond->wait(mutex);
mutex->unlock();
}
To copy to clipboard, switch view to plain text mode
If I run this on a data set of about 4000 around 3500 are inserted correctly, however, there are about 500 signals from the main thread that get to the slot, and wakeOne, but nothing happens (the forever loop doesn't get woken). Why is this?
Bookmarks