Hello; I'm writing a Gui that use lib callbacks where I have no control of them. I have created a class that inherits from QWidget and

library listener so when something happens, this function is called by the library:
Qt Code:
  1. class MyClass : public QWidget, public LibraryListener
  2. {
  3. MyClass(QWidget *parent = 0) : QWidget(parent)
  4. {
  5. Library::getIstance()->addListener(this); // add the listener
  6. }
  7. }
  8.  
  9. void MyClass::on(Listener::listener, Object *o)
  10. {
  11. emit signal(o);
  12. }
To copy to clipboard, switch view to plain text mode 

Library lives in own thread and it usually starts others. I know Qt complains if the sender's and receiver's thread ae different. Infact

application is killed with the following error:
ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread. Current thread 2aaaac07be40.

Receiver 'updateButton' (of type 'QPushButton') was created in thread 6a9db0", file kernel/qcoreapplication.cpp, line 274
It usually works and it usually don't. Why doesn't this problem happen always?

I think I should create a new class that inherits from QThread and this class through queued signals handles lib thread. Am I wrong?

Thank your your answer