Hi,

Im having some problems with cross thread communication, basically i get an assert error:

"ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 72fc768. Receiver 'ProDialog' (of type 'progressDlg') was created in thread 50d4058", file kernel\qcoreapplication.cpp, line 296"
Im using signals/slots to send data from the new thread to the ProDialog instance, and im not sure why it doesn't like it :confused the only shared object is the container instance, i havent bothered locking/unlocking this as I know its not in use while the thread is executing, hopefully thats good enough.

Heres some code extracts:

Main window code:
Qt Code:
  1. // Create progress dialog
  2. pro = new progressDlg();
  3. pro->show();
  4.  
  5. // Spawn a new worker thread
  6. enc = new TEnc;
  7.  
  8. // Connect signals/slots
  9. connect(enc, SIGNAL(StartingFile(QString)), pro, SLOT(setProgressLabel(const QString&)), Qt::DirectConnection);
  10. connect(enc, SIGNAL(AddFilesDone(bool)), this, SLOT(AddFilesComplete(bool)));
  11. connect(enc, SIGNAL(Progress(int, int)), pro, SLOT(setProgress(int, int)), Qt::DirectConnection);
  12.  
  13. enc->setParams(container, files);
  14. enc->start(); // start the thread
To copy to clipboard, switch view to plain text mode 


The TEnc object (QThread subclass)
Qt Code:
  1. void TEnc::run()
  2. {
  3. emit Progress(files.size(), 0);
  4.  
  5. // do the work
  6. for(int i = 0; i < files.size(); i++)
  7. {
  8. bits = files.at(i).split("/"); // extract file name from path
  9. if(bits.size() == 0)
  10. bits = files.at(i).split("\\");
  11.  
  12. if(bits.size() != 0)
  13. emit StartingFile("[" + QString::number(i+1) + "/" + QString::number(files.size()) + "] " + bits.at(bits.size() - 1)); // send signal out that we are starting
  14.  
  15. if(!container->AddItem(files.at(i).toAscii(), NULL))
  16. {
  17. emit AddFilesDone(false); // fail with error
  18. return;
  19. }
  20.  
  21. emit Progress(files.size(), i + 1); // update progress
  22. }
  23.  
  24. // all done signal
  25. emit AddFilesDone(true); // singal -> all files done
  26. }
To copy to clipboard, switch view to plain text mode 

Any ideas what silly mistake ive made this time

Thanks,

Jack