
Originally Posted by
jacek
You don't invoke beginInsertRows() and endInsertRow() in MyGameModel::insertRow().
This shouldn't influence the speed so much.
My guess is, apart from anything else, that the other thread may be starving the model. Is this other thread really necessary? Or maybe you could add data by blocks and not one by one? Hundred messages per second need to be inserted into the queue and retrieved from it and processed, that's much work. Maybe you could use something like this:
QList<TabbedDataParser*> sharedlist;
// "worker" thread:
mutex.lock();
bool needSignal = sharedlist.isEmpty();
sharedlist << new TabbedDataParser(...);
if(needSignal) emit newData();
mutex.unlock();
// "gui" thread
void GUIThreadClass::slotConnectedToNewData(){
mutex.lock();
while(!sharedlist.isEmpty()){
TabbedDataParser *elem = sharedlist.front();
sharedlist.pop_front();
processData(elem);
}
mutex.unlock();
}
QMutex mutex;
QList<TabbedDataParser*> sharedlist;
// "worker" thread:
mutex.lock();
bool needSignal = sharedlist.isEmpty();
sharedlist << new TabbedDataParser(...);
if(needSignal) emit newData();
mutex.unlock();
// "gui" thread
void GUIThreadClass::slotConnectedToNewData(){
mutex.lock();
while(!sharedlist.isEmpty()){
TabbedDataParser *elem = sharedlist.front();
sharedlist.pop_front();
processData(elem);
}
mutex.unlock();
}
To copy to clipboard, switch view to plain text mode
You can still improve it. The code I wrote blocks the worker thread while the main thread processes data. You can make it that the list is only locked by the main thread when it actually retrieves data from it and when it processes the data, the other thread could still insert new items. Something like this could work:
void GUIThreadClass::slotConnectedToNewData(){
forever{
mutex.lock();
if(sharedlist.isEmpty()){
mutex.unlock(); break;
}
TabbedDataParser *elem = sharedlist.front();
sharedlist.pop_front();
mutex.unlock();
processData(elem);
}
}
void GUIThreadClass::slotConnectedToNewData(){
forever{
mutex.lock();
if(sharedlist.isEmpty()){
mutex.unlock(); break;
}
TabbedDataParser *elem = sharedlist.front();
sharedlist.pop_front();
mutex.unlock();
processData(elem);
}
}
To copy to clipboard, switch view to plain text mode
This way instead of emitting 200 signals (which end up in the event queue), you emit one or two.
Bookmarks