View Full Version : QThread for GUI speed up and event error

23rd September 2009, 12:50
In my program I create few tab with custom widget/view inside.
In one of those widget I populate entire view with persistent editor during start-up procedure. I noticed that this procedure takes to much time and create another thread to handle openPersistentWidget.
But, unfortunately, another problem arise. Almost immediately program crashes and assert shows.

Cannot send events to objects owned by a different thread

Code performed inside this thread is

QMutexLocker locker(&mutex);
int iColumnCount = m_ptResearchDlg->cResearchModel.columnCount();
int iRowCount = m_ptResearchDlg->cResearchModel.rowCount();
for(int j=0;j<iColumnCount;j++)
for(int i=0;i<iRowCount;i++)
QModelIndex sIndex;
sIndex = m_ptResearchDlg->cResearchModel.index(i,j);
int iEnum = m_ptResearchDlg->cResearchModel.data(sIndex,eEnumValueRole).toInt() ;
if (iEnum<0) continue;

After that, during program execution, raise() function sends QEvent::ZOrderChange to receiver placed in main thread, but QThread::currentThread() says that newly created thread is the current one.

How to solve this problem?
And furthermore - how to create GUI elements in separate threads to avoid synchronization problems (because this situation isn't the first problem with threads and UI)?