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. How to queue the invocation of a slot instead of calling directly ?
Forum Updated to NodeBB v4.3 + New Features

How to queue the invocation of a slot instead of calling directly ?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 3 Posters 1.0k 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.
  • GianlucaG Offline
    GianlucaG Offline
    Gianluca
    wrote on last edited by
    #1

    Dear all,
    with the QMetaObject from C++ it is possible to use the invokeMethod with the option to queue the invocation to the event thread instead of calling immediately.
    I'm wondering if there is an analogous mechanism on the QML side.

    Thanks,
    Gianluca.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on last edited by
      #2

      Not directly. There was a WIP patch to add Qt.later() and Qt.after() functions to the Qt global object, to allow this use-case, but it couldn't handle the case where the context got deleted out from underneath it gracefully.

      The closest you can do is create a Timer object with a timeout of 1 millisecond (actually, 0 might work, not sure), and invoke the function in the onTriggered / onTimeout or whatever it's called, handler.

      @
      Timer {
      id: fnQueue
      property var queuedFunction
      interval: 1
      onTriggered: { queuedFunction.call() }
      }

      // some imperative code...
      fnQueue.queuedFunction = someFunc;
      fnQueue.start()
      @

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thoughthorizon
        wrote on last edited by
        #3

        [quote author="chrisadams" date="1402025578"]
        The closest you can do is create a Timer object with a timeout of 1 millisecond (actually, 0 might work, not sure), and invoke the function in the onTriggered / onTimeout or whatever it's called, handler.

        @[/quote]

        Agreed, without adding additional underlying code this is probably the best solution. An interval of 0 works for this too, in my experience.

        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