Results 1 to 4 of 4

Thread: tcpSocket and threads: Cannot create children for a parent that is in a different thr

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Posts
    31
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Post tcpSocket and threads: Cannot create children for a parent that is in a different thr

    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

    Qt Code:
    1. queueProg::queueProg(QString ipAddress, quint16 ipPort, quint8 dutNumber, tOpCode opCode)
    2. {
    3. ......
    4. this->tcpSocket = new QTcpSocket(this);
    5. connect(tcpSocket, SIGNAL(connected()), this, SLOT(sendMsg()));
    6. connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readMsg()));
    7. connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
    8. this, SLOT(handleSocketError(QAbstractSocket::SocketError)));
    To copy to clipboard, switch view to plain text mode 

    2. overload the run method as required

    Qt Code:
    1. void queueProg::run()
    2. {
    3. this->tcpSocket->abort(); // just reset the connection
    4. this->tcpSocket->connectToHost(this->ipAddress, this->ipPort);
    5. exec();
    6. return;
    7. }
    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

    Qt Code:
    1. queueProg *picQueueProg =
    2. new queueProg(this->ipAddress, this->ipPort, this->dutNr, PICPROG);
    3. queueProg *mceQueueProg =
    4. 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
    Last edited by wysota; 18th March 2011 at 19:24. Reason: missing [code] tags

Similar Threads

  1. Replies: 0
    Last Post: 14th April 2010, 15:03
  2. disable a parent and children in a tree model
    By qt_gotcha in forum Newbie
    Replies: 4
    Last Post: 9th July 2009, 06:49
  3. Replies: 6
    Last Post: 8th July 2009, 13:24
  4. Replies: 4
    Last Post: 1st May 2009, 11:00
  5. Replies: 3
    Last Post: 29th May 2008, 13:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.