hi
using visual studio 2008 and Qt 4.7.1, i am facing the weird warning from QOBJECT "Cannot create children for a parent that is in a different thread.". i cannot afford to understand this explainaition :-) athttp://cep.xor.aps.anl.gov/software/qt4-x11-4.2.2-browser/dc/d4f/class_q_object.html so here i am :-)
i created a thread which redefines the runmerìthod as stated in the documentation.
major steps are
1. I create the QTcp socket in the new thread class constructor nd connect the relavant signals. the network connection has already been created by the main application
queueProg
::queueProg(QString ipAddress, quint16 ipPort, quint8 dutNumber, tOpCode opCode
){
......
connect(tcpSocket, SIGNAL(connected()), this, SLOT(sendMsg()));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readMsg()));
queueProg::queueProg(QString ipAddress, quint16 ipPort, quint8 dutNumber, tOpCode opCode)
{
......
this->tcpSocket = new QTcpSocket(this);
connect(tcpSocket, SIGNAL(connected()), this, SLOT(sendMsg()));
connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readMsg()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
this, SLOT(handleSocketError(QAbstractSocket::SocketError)));
To copy to clipboard, switch view to plain text mode
2. overload the run method as required
void queueProg::run()
{
this->tcpSocket->abort(); // just reset the connection
this->tcpSocket->connectToHost(this->ipAddress, this->ipPort);
exec();
return;
}
void queueProg::run()
{
this->tcpSocket->abort(); // just reset the connection
this->tcpSocket->connectToHost(this->ipAddress, this->ipPort);
exec();
return;
}
To copy to clipboard, switch view to plain text mode
3. create TWO class object of this thread which open TCP sockets at the same address but different ports
queueProg *picQueueProg =
new queueProg(this->ipAddress, this->ipPort, this->dutNr, PICPROG);
queueProg *mceQueueProg =
new queueProg(this->ipAddress, this->ipPort+1, this->dutNr, MCEPROG);
queueProg *picQueueProg =
new queueProg(this->ipAddress, this->ipPort, this->dutNr, PICPROG);
queueProg *mceQueueProg =
new queueProg(this->ipAddress, this->ipPort+1, this->dutNr, MCEPROG);
To copy to clipboard, switch view to plain text mode
There is no black magic: i get this strategy by looking at various example in the web: it could be i probably mixed them wrongly :-)
maybe the tcpSocket is silently associated to another thread when creatd a new tcpsocket object ...
more runtime errors here
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTcpSocket(0xbd9d90), parent's thread is QThread(0xa88ce0), current thread is queueProg(0xa89180)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTcpSocket(0xbd9d90), parent's thread is QThread(0xa88ce0), current thread is queueProg(0xa89180)
what about debuggin threads? can debug mode be safely used or is too much invasive?
thanks much for your help
Bookmarks