Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject: Cannot create children for a parent that is in a different thread
Qt 6.11 is out! See what's new in the release blog

QObject: Cannot create children for a parent that is in a different thread

Scheduled Pinned Locked Moved Solved General and Desktop
qttcpsocket
3 Posts 2 Posters 475 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    weigang.lee
    wrote on last edited by
    #1

    hello, I want to use "QtcpSocket" and "movetoThread" to detach from qt main thread. and then I executed "connecttohost(....)" but the executed result shows that "QObject: Cannot create children for a parent that is in a different thread.
    (Parent is QTcpSocket(0x1de2b6796e0), parent's thread is QThread(0xbca74ffc00), current thread is QThread(0x1de2b60ee70)" . Does Anybody knows the reason?lQLPJwPr7hm9rpQuzQJSsFiM_uoP6rQCA-lYf9eA4AA_594_46.png_720x720q90g.jpg

    Christian EhrlicherC 1 Reply Last reply
    0
    • W weigang.lee

      hello, I want to use "QtcpSocket" and "movetoThread" to detach from qt main thread. and then I executed "connecttohost(....)" but the executed result shows that "QObject: Cannot create children for a parent that is in a different thread.
      (Parent is QTcpSocket(0x1de2b6796e0), parent's thread is QThread(0xbca74ffc00), current thread is QThread(0x1de2b60ee70)" . Does Anybody knows the reason?lQLPJwPr7hm9rpQuzQJSsFiM_uoP6rQCA-lYf9eA4AA_594_46.png_720x720q90g.jpg

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      When you move your socket to another thread then you should also access the socket from this thread and not from the main thread.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      W 1 Reply Last reply
      4
      • Christian EhrlicherC Christian Ehrlicher

        When you move your socket to another thread then you should also access the socket from this thread and not from the main thread.

        W Offline
        W Offline
        weigang.lee
        wrote on last edited by
        #3

        @Christian-Ehrlicher thanks. it had solved.

        1 Reply Last reply
        0
        • W weigang.lee has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved