Results 1 to 5 of 5

Thread: [QTcpSocket] Cannot create children for a parent that is in a different thread

  1. #1
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default [QTcpSocket] Cannot create children for a parent that is in a different thread


  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [QTcpSocket] Cannot create children for a parent that is in a different thread

    Your MyThread instance is in a different thread than the "socket" instance it contains but you are calling the socket's write method without any thread change.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [QTcpSocket] Cannot create children for a parent that is in a different thread

    Could you please tell me how?
    I tried using movetothread() and changing my signals&slots but I could not figure it out...

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [QTcpSocket] Cannot create children for a parent that is in a different thread

    You could send the data to an object that lives in the second thread, e.g. connecting a signal of MyThread to a slot of such an object and emitting that from MyThread::writeData() or calling that slot via QMetaObject::invokeMethod.

    Alternatively you could split MyThread into a normal QObject subclass that provides the API you connect to and move that into a plain QThread instance.

    Alternatively you could try thread->moveToThread(thread) and not pass "this" to the MyThread constructor

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    SteveJ (26th January 2016)

  6. #5
    Join Date
    Jan 2016
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: [QTcpSocket] Cannot create children for a parent that is in a different thread

    Quote Originally Posted by anda_skoa View Post
    Alternatively you could try thread->moveToThread(thread) and not pass "this" to the MyThread constructor
    _
    This was the easiest way to fix it for me. Thank you !!!

Similar Threads

  1. Replies: 5
    Last Post: 26th May 2014, 07:13
  2. Replies: 6
    Last Post: 22nd December 2011, 21:03
  3. Replies: 3
    Last Post: 19th March 2011, 15:01
  4. Replies: 6
    Last Post: 8th July 2009, 13:24
  5. Replies: 4
    Last Post: 1st May 2009, 11:00

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.