1

I have 2 threads which each create a new QTcpSocket in the run method(). I connect the two threads together widh a signal/slot like:

connect(thread1, SIGNAL(foo()), thread2, SLOT(bar()));

But when I want to use the socket from thread2 in bar slot I keep getting this error message:

"QSocketNotifier: Socket notifiers cannot be enabled or disabled from another thread"

Additional info:

  • thread1 and thread2 are both objects of the same class.
  • I used qDebug to check if the socket from bar slot is really the socket from thread2 (it is).

I want to know if anyone knows what am I doing wrong and why.

Thank you, qwerty

Daan
  • 940
  • 10
  • 22
qwerty
  • 11
  • 2
  • 1
    You're trying to use a `QSocketNotifier` that exists on one thread from a different thread. To diagnose the problem any further you'll need to provide a [mcve]. – G.M. Jun 25 '17 at 17:01
  • As @G.M. states, an MCVE will much improve your questions, as at present, we can only guess as to what is wrong. It sounds like you're inheriting from `QThread`. I suggest following the method as outlined in [this article](https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/). – TheDarkKnight Jun 26 '17 at 08:29
  • Ok, I will try to provide a MCVE later today, thanks for answer so far. – qwerty Jun 26 '17 at 10:34

0 Answers0