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. Error QObject::setParent: Cannot set parent, new parent is in a different thread

Error QObject::setParent: Cannot set parent, new parent is in a different thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 15.7k 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.
  • D Offline
    D Offline
    developerNancy
    wrote on last edited by
    #1

    error while uploading file on server in qt application crashed and got error
    QObject::setParent: Cannot set parent, new parent is in a different thread

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thesourcehim
      wrote on last edited by
      #2

      It means exactly what is says. The entire object hierarchy has to be in the same thread. Object's thread is defined when the object is created inside that thread. You can't create an object with parent that was created from different thread and you can't reparent object if the parent is in different thread. In this case you should move one of these objects (parent or child) to the same thread with QObject::moveToThread or use new object without parent at all. Note a few things if you decide to move object:

      1. If object has parent, you can't move it.
      2. If object has children, moving it to the different thread will move the entire hierarchy too.
      3. You can push object to the different thread, but you can't pull it, i.e. you must call moveToThread from the current object's thread.
      4. When using signal-slot queued connections, note that object's slots are executed within the event loop of current object's thread, so if you move the object, it's slots will be executed in a new thread (assuming you have event loop there).
      1 Reply Last reply
      3

      • Login

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