SIGNAL / SLOT problem

jeffreyg used Ask the Experts™
I am a newbie to KDevelop (2 weeks) and I am trying to write a class that accepts data from a socket. I have implemented the following code:

// Header file
#include <qsocket.h>

class QSocketClass : public QSocket

    bool connectSocket(QString &host, Q_UINT16 port);
    void sendToServer(QString str);
    void ProcessPendingRead();
    void closeSocket();

  private slots:
    void socketReadyRead();

    QDataStream dataStream;

// C++ file

#include "KioskDemo.h"
#include "Socket.h"

extern KioskDemo *theApp;

  printf("In the QSocketClass constructor\n");

  printf("In the QSocketClass destructor\n");


bool QSocketClass::connectSocket(QString &host, Q_UINT16 port)
  printf("trying to connect to the socket host - " + host + "\n");
  if (!theApp->socket)
    theApp->AfxMessageBox("Out of memory");

  connect(theApp->socket, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
  theApp->socket->connectToHost(host, port);


void QSocketClass::socketReadyRead()
  QCString s;
  theApp->socket->readBlock(, theApp->socket->bytesAvailable());

  printf(s + "\n");


void QSocketClass::sendToServer(QString str)
  // write to the server
  printf("Sending to socket server : " + str + "\n");

  dataStream.writeBytes(str, str.length());


Now this compiles and I can send information to the socket port and the application at the other end picks it up and responds by squiting data back.

However I get the following message when I run the app :

QObject::connect: No such slot QSocket::socketReadyRead()
QObject::connect: (sender name: 'unnamed')
QObject::connect: (reciever name: 'unnamed')

I tried a demo on the web : that incorporated the readyRead() method and it works but I cannot see the difference between the two app in terms of this readyRead() function. Is this because it inherits from QSocket? how can I force it to look at the QSocketClass for the function and not search in QSocket?

regards in advance,

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006

Ok, i got your problem ... took me a while to figure out but I think I have identified it ..

there is no member called socket in your class ... also you are deriving from the QSocket which has a member called socket ...
since you are receiving signal on socket, the SLOT cannot be at the child ( it will not be visible to the parent )

to get rid of the problem, add a member ot type QSocket called socket in your QSocketClass and restructure just like shown in the SMTP example which you have posted ...

Okay, the problem most likely has to do with the slot socketReadyDead() being private. You have to make it protected, or even public.

Let me know if this was indeed the problem, since I don't have the oppertunity to reproduce the problem at the moment.
Okay back again, i reviewed it and noticed something VERY important! You don't have Q_OBJECT in your class prototype! Add it and it will work (perhaps you also have to make the slot protected though)

Good luck! :)



Seeing u talk about the Q-OBJECT I placed the readyRead() event in the main application windows and have passed my socket message through the app into the relevant sub application. Also made the readyRead() a public SLOT.



Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial