I am new to multithreading. It seems many people have a similar problem. I searched a lot for an answer. However, I cannot figure out why I get the following error in my case:
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 26ff4538. Receiver '' (of type 'RuleSetVerifier') was created in thread 90b6c0", file kernel\qcoreapplication.cpp, line 553
From my main thread I start a QRunnable thread:
ConditionAnalysisManager* analysisManager = new ConditionAnalysisManager(param1, param2);
connect(analysisManager, SIGNAL(conditionAnalysisResultReady(const QString&, int, bool, QMap<QString, bool>, const QString&)), this, SLOT(evaluateAnalysisResult(const QString&, int, bool, QMap<QString, bool>, const QString&)));
QThreadPool::globalInstance()->start(analysisManager);
The result calculated in the thread are sent back to the main thread via a signal/slot connection. In the ConditionAnaylsisManager I do the following:
void ConditionAnalysisManager::run()
{
this->analyzeConditions(param1, param2);
}
void ConditionAnalysisManager::analyzeConditions(int hostId, const QString& param2)
{
//calculations
emit conditionAnalysisResultReady(uid, hostId, finalResult, ruleSetResults, finalDataString);
}
The Alert happens when the signal is emitted. I tried to implement it as described in http://wiki.qt.io/Threads_Events_QObjects#Signals_and_slots_across_threads
As far as I understand it is possible to call a slot in the main thread from a thread. I tried with Qt::QueuedConnection and with default. I always get the Alert. Why?? What is wrong in my case?
In the constructor of the ConditionAnalysisManager class that inherits QRunnable I create an object of a helper class which does not inherit from QRunnable.
this->m_ruleSetVerifier = new RuleSetVerifier(param1, param2);
I mention this because the Alert says " Current thread 26ff4538. Receiver '' (of type 'RuleSetVerifier')". I cannot understand why the thread is of type RuleSetVerifier and not of type ConditionAnaylsisManager since the signal is emitted from the ConditionAnalysisManager. What is wrong??
I am looking forward to your help. Thank you!