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.
Qt Code:
  1. Cannot send events to objects owned by a different thread
To copy to clipboard, switch view to plain text mode 

Code performed inside this thread is
Qt Code:
  1. QMutexLocker locker(&mutex);
  2. int iColumnCount = m_ptResearchDlg->cResearchModel.columnCount();
  3. int iRowCount = m_ptResearchDlg->cResearchModel.rowCount();
  4. for(int j=0;j<iColumnCount;j++)
  5. for(int i=0;i<iRowCount;i++)
  6. {
  7. QModelIndex sIndex;
  8. sIndex = m_ptResearchDlg->cResearchModel.index(i,j);
  9. int iEnum = m_ptResearchDlg->,eEnumValueRole).toInt();
  10. if (iEnum<0) continue;
  11. m_ptResearchDlg->researchView->openPersistentEditor(sIndex);
  12. }
To copy to clipboard, switch view to plain text mode 

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)?