Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Bind QObject created in different thread to QML interface ran in main thread

Bind QObject created in different thread to QML interface ran in main thread

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 3.5k 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.
  • M Offline
    M Offline
    miks131
    wrote on last edited by
    #1

    Hi guys,

    I'm writing QtQuick application, I defined C++ class, with Q_PROPERTIES, then registered class, and now able to call its method and properties from QML code.

    But I ran into troubles. I have asynchronies communication with a server. In main thread I'm calling 'getServerData' function, which is non-blocking, I also has an event triggered from different thread onGetServerData()

    When I got data from server, I'm creating bunch of QCustomFile objects, and updating interface. ( Binding their properties to QML ). And here is a problem, since QCustomFile objects were created in different thread, runtime error is raised by Qt Framework:

    @QQmlEngine: Illegal attempt to connect to QCustomFile(0x104299780) that is in a different thread than the QML engine QQmlApplicationEngine(0x7fff5fbff5b8)@

    Does anyone know, how to update QML interface from different thread?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      laureon
      wrote on last edited by
      #2

      First your QCustomFile must be a QObject child. Create and load your QCustomFile on your thread, then use QObject::moveToThread(<GET YOU MAIN THREAD HERE>). Then you send it through a signal to your main thread... Hope it works for you..

      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