Hi,
Im having some problems with cross thread communication, basically i get an assert error:
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.Quote:
"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"
Heres some code extracts:
Main window code:
Code:
// Create progress dialog pro = new progressDlg(); pro->show(); // Spawn a new worker thread enc = new TEnc; // Connect signals/slots connect(enc, SIGNAL(StartingFile(QString)), pro, SLOT(setProgressLabel(const QString&)), Qt::DirectConnection); connect(enc, SIGNAL(AddFilesDone(bool)), this, SLOT(AddFilesComplete(bool))); connect(enc, SIGNAL(Progress(int, int)), pro, SLOT(setProgress(int, int)), Qt::DirectConnection); enc->setParams(container, files); enc->start(); // start the thread
The TEnc object (QThread subclass)
Code:
void TEnc::run() { emit Progress(files.size(), 0); QStringList bits; // do the work for(int i = 0; i < files.size(); i++) { bits = files.at(i).split("/"); // extract file name from path if(bits.size() == 0) bits = files.at(i).split("\\"); if(bits.size() != 0) if(!container->AddItem(files.at(i).toAscii(), NULL)) { emit AddFilesDone(false); // fail with error return; } emit Progress(files.size(), i + 1); // update progress } // all done signal emit AddFilesDone(true); // singal -> all files done }
Any ideas what silly mistake ive made this time :o
Thanks,
Jack