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. [SOLVED] Pass QObject * (and all its signals) to qml through function (NOT via setContextProperty)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Pass QObject * (and all its signals) to qml through function (NOT via setContextProperty)

Scheduled Pinned Locked Moved QML and Qt Quick
4 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.
  • D Offline
    D Offline
    DimanNe
    wrote on 7 Dec 2013, 13:11 last edited by
    #1

    I am trying to implement progress bars like ones in QtCreator (when building or indexing or searching).
    So, I have
    @QFutureWatcher<something> *Watcher@

    on C++ side and I want to expose all its signals (progressValueChanged(), started(), and so on...) to some qml type, which will react to these signals and display progress on the screen.

    So, how can I pass Watcher pointer to qml side?

    Note, I can not use setContextProperty because I must give names to every Watcher! But I even do not know how much Wathcer's will be created at run-time.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DimanNe
      wrote on 7 Dec 2013, 13:26 last edited by
      #2

      Seems, I guessed one (but not very beautiful) decision.

      I can connect signal of Watcher to C++-side slots, in which I will ::invokeMethod() of qml component...

      So, is there "more native" decision?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Torgeir
        wrote on 8 Dec 2013, 20:00 last edited by
        #3

        [quote author="DimanNe" date="1386421880"]I am trying to implement progress bars like ones in QtCreator (when building or indexing or searching).

        ...

        But I even do not know how much Watcher's will be created at run-time.[/quote]

        I would create a QAbstractListModel for this, with a list of QFutureWatchers. This could have a role for progressPercentage. Every time a QFutureWatcher is created, it is added to the model and every time one finishes, it is removed.

        Then in Qml you could use it like this:
        @
        Column {
        spacing: 5
        Repeater {
        model: progressModel
        Rectangle {
        width: progressPercentage
        * 200 / 100
        height: 15
        color: "blue"
        }
        }
        }
        @

        As you can see, for the progressbars you don't even need to expose the full QFutureWatchers into Qml. Though, if you need, you could add a role that returns a QObject * in a QVariant. That would give you full access to any signals in the QFutureWatcher.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DimanNe
          wrote on 8 Dec 2013, 20:12 last edited by
          #4

          Thanks, seems it is ok

          1 Reply Last reply
          0

          1/4

          7 Dec 2013, 13:11

          • Login

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