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. Moving an object to a different thread
Forum Updated to NodeBB v4.3 + New Features

Moving an object to a different thread

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    paksas
    wrote on last edited by
    #1

    Hi

    My application uses a custom serialization mechanism.
    Phase 1) The mechanism loads clusters of data on a separate thread, creates all appropriate objects there and so on.
    Phase 2) Once they are all fully deserialized, it hands them over to the main application thread and finishes the serialization there by for example setting up connections between objects etc.

    This mechanism is a new addition to my framework - before that I was deserializing everything on the main thread.

    The problem I have is that some of the objects that are created during deserializatiuon are Qt objects ( a bunch of widgets basically ).
    They all record the ids of a thread they were created on. And when the time comes for "phase 2", these objects start complaing that they all don't belong to this thread and therefore can have no signals sent etc.

    So I found a method on QObject, called 'moveToThread'. The little bugger's not very helpful though, as it performs a check and prevents from moving objects from a different thread to the current thread ( WHY scuh a constraint, I have no clue ).

    Does anyone have an idea how can I go about this? I can guarantee that the objects will only be createad on a separate thread, and from that point on they will all be living and operating on the main thread.

    Thanks,
    Paksas

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Call moveToThread() from the current thread to "push" the object to a different thread. Qt has that constraint because it's dangerous to "pull" an object from a different thread: What will happen if the object is moved, while it is in the middle of processing data in its original thread?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0

      • Login

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