0

I have created a simple threaded network server. The main.cpp calls app.exec() to idle, and the thread fires off as expected once I establish a connection.

In the thread's run() function, I hookup a signal from readyRead to a slot called readCommand:

connect(tcpSocketPtr, SIGNAL(readyRead()), this, SLOT(readCommand()) );

and I have defined the readCommand in the .h file for the class, as a "private slot" - since it is only called from within the class. Hope that's right.

after the connect above, the run() function returns. There is no app.exec() call or anything. Could that be the problem? Do I have to call some function to cause the thread to listen for signals?

When I send text to the port the readCommand function never fires...and I have no idea how to debug this..suggestions?

László Papp
  • 51,870
  • 39
  • 111
  • 135
TSG
  • 4,242
  • 9
  • 61
  • 121

1 Answers1

0

and I have defined the readCommand in the .h file for the class, as a "private slot" - since it is only called from within the class. Hope that's right.

Yes, that looks correct.

However, you should use int QThread::exec() [protected] inside the void QThread::run() [virtual protected] method to start the thread execution as opposed to returning almost instantly.

László Papp
  • 51,870
  • 39
  • 111
  • 135