I have a thread and a tcpSocket. The tcpSocket is declared in my "x.h" class.
At some point I want to use this tcpSocket, but I get this message:
ASSERT failure in QObject::QObject(): "Cannot create children for a parent that is in a different thread.", file kernel/qobject.cpp, line 599
This is the code where I create my tcpSocket:
	
	void Client :: run()
{
     cout << "void Client :: run()\n";
     if(!tcpSocket->setSocketDescriptor(socketDescriptor))
     {
          cout << "Error - tcpSocket descriptor\n";
          return;
     }
     connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
     connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
     exec();
}
        void Client :: run()
{
     cout << "void Client :: run()\n";
     tcpSocket = new QTcpSocket();    
     if(!tcpSocket->setSocketDescriptor(socketDescriptor))
     {
          cout << "Error - tcpSocket descriptor\n";
          return;
     }
     connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readData()));
     connect(tcpSocket, SIGNAL(disconnected()), this, SLOT(clientDisconnected()));
     exec();
}
To copy to clipboard, switch view to plain text mode 
  
This is the code where I want my tcpSocket to write to another computer:
	
	void Client 
:: loginResponse(bool accepted, 
QString *userName, 
QByteArray *messageOut
) {
     if(accepted==true)
     {
          server->addClient(*userName, this);
          clientLogged = true;
          tcpSocket->write("hello\n");
     }
}
        void Client :: loginResponse(bool accepted, QString *userName, QByteArray *messageOut)
{
     if(accepted==true)
     {
          server->addClient(*userName, this);
          clientLogged = true;
          tcpSocket->write("hello\n");
     }
}
To copy to clipboard, switch view to plain text mode 
  
How can i refer to the tcpSocket that was instantiated in the run() ?
				
			
Bookmarks