[SOLVED] Pass QObject * (and all its signals) to qml through function (NOT via setContextProperty)
-
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.
-
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?
-
[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.
-
Thanks, seems it is ok