QT QML Accessing Attached Property From Another QML Object
up vote
-1
down vote
favorite
main.qml:
import QtQuick 2.11
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow
id: window
x: 200
y: 200
visible: true
Component
id: firstViewComponent
FirstView
id: firstView
StackView
id: stackView
anchors.fill: parent
Component.onCompleted: push(firstViewComponent)
Timer
interval: 1000
running: true
onTriggered: stackView.pop()
FirstView.qml:
Rectangle
id: view
StackView.onDeactivating: console.log('view: view is deactivating')
ListModel
id: aModel
ListElement
name: 'Element 0'
ListElement
name: 'Element 1'
ListView
id: listView
model: aModel
delegate: Rectangle
id: listViewDelegate
Connections
target: view.StackView // <---- DOESN'T WORK
onDeactivating: console.log('delegate ' + index + ': needs to do some housekeeping now')
I have a view that is instantiated by a StackView in main.qml. The StackView attaches a signal StackView.onDeactivating to the view. Is there any way to attach to the signal from an object other than the one the signal is attached to? I need to do some cleanup in listViewDelegate when the view is popped.
I could have view emit its own signal, and have the delegate respond to that signal. But what I'm wondering is if there is a way to connect to the attached signal: StackView.onDeactivating from a different object (listViewDelegate).
qt qml attached-properties
|
show 11 more comments
up vote
-1
down vote
favorite
main.qml:
import QtQuick 2.11
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow
id: window
x: 200
y: 200
visible: true
Component
id: firstViewComponent
FirstView
id: firstView
StackView
id: stackView
anchors.fill: parent
Component.onCompleted: push(firstViewComponent)
Timer
interval: 1000
running: true
onTriggered: stackView.pop()
FirstView.qml:
Rectangle
id: view
StackView.onDeactivating: console.log('view: view is deactivating')
ListModel
id: aModel
ListElement
name: 'Element 0'
ListElement
name: 'Element 1'
ListView
id: listView
model: aModel
delegate: Rectangle
id: listViewDelegate
Connections
target: view.StackView // <---- DOESN'T WORK
onDeactivating: console.log('delegate ' + index + ': needs to do some housekeeping now')
I have a view that is instantiated by a StackView in main.qml. The StackView attaches a signal StackView.onDeactivating to the view. Is there any way to attach to the signal from an object other than the one the signal is attached to? I need to do some cleanup in listViewDelegate when the view is popped.
I could have view emit its own signal, and have the delegate respond to that signal. But what I'm wondering is if there is a way to connect to the attached signal: StackView.onDeactivating from a different object (listViewDelegate).
qt qml attached-properties
1
what ismyView
?, please provide a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 10 at 18:14
check this answer
– Redanium
Nov 10 at 21:15
@eylianesc correcting.
– Colin
Nov 10 at 21:52
still correcting..@Redanium I have a basic understanding of qml and js, this pertains to accessing an Attached Property, which is a qml concept.
– Colin
Nov 10 at 21:56
@eylianesc corrected.
– Colin
Nov 10 at 22:12
|
show 11 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
main.qml:
import QtQuick 2.11
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow
id: window
x: 200
y: 200
visible: true
Component
id: firstViewComponent
FirstView
id: firstView
StackView
id: stackView
anchors.fill: parent
Component.onCompleted: push(firstViewComponent)
Timer
interval: 1000
running: true
onTriggered: stackView.pop()
FirstView.qml:
Rectangle
id: view
StackView.onDeactivating: console.log('view: view is deactivating')
ListModel
id: aModel
ListElement
name: 'Element 0'
ListElement
name: 'Element 1'
ListView
id: listView
model: aModel
delegate: Rectangle
id: listViewDelegate
Connections
target: view.StackView // <---- DOESN'T WORK
onDeactivating: console.log('delegate ' + index + ': needs to do some housekeeping now')
I have a view that is instantiated by a StackView in main.qml. The StackView attaches a signal StackView.onDeactivating to the view. Is there any way to attach to the signal from an object other than the one the signal is attached to? I need to do some cleanup in listViewDelegate when the view is popped.
I could have view emit its own signal, and have the delegate respond to that signal. But what I'm wondering is if there is a way to connect to the attached signal: StackView.onDeactivating from a different object (listViewDelegate).
qt qml attached-properties
main.qml:
import QtQuick 2.11
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow
id: window
x: 200
y: 200
visible: true
Component
id: firstViewComponent
FirstView
id: firstView
StackView
id: stackView
anchors.fill: parent
Component.onCompleted: push(firstViewComponent)
Timer
interval: 1000
running: true
onTriggered: stackView.pop()
FirstView.qml:
Rectangle
id: view
StackView.onDeactivating: console.log('view: view is deactivating')
ListModel
id: aModel
ListElement
name: 'Element 0'
ListElement
name: 'Element 1'
ListView
id: listView
model: aModel
delegate: Rectangle
id: listViewDelegate
Connections
target: view.StackView // <---- DOESN'T WORK
onDeactivating: console.log('delegate ' + index + ': needs to do some housekeeping now')
I have a view that is instantiated by a StackView in main.qml. The StackView attaches a signal StackView.onDeactivating to the view. Is there any way to attach to the signal from an object other than the one the signal is attached to? I need to do some cleanup in listViewDelegate when the view is popped.
I could have view emit its own signal, and have the delegate respond to that signal. But what I'm wondering is if there is a way to connect to the attached signal: StackView.onDeactivating from a different object (listViewDelegate).
qt qml attached-properties
qt qml attached-properties
edited Nov 10 at 22:25
eyllanesc
67.6k82952
67.6k82952
asked Nov 10 at 18:12
Colin
1,5421926
1,5421926
1
what ismyView
?, please provide a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 10 at 18:14
check this answer
– Redanium
Nov 10 at 21:15
@eylianesc correcting.
– Colin
Nov 10 at 21:52
still correcting..@Redanium I have a basic understanding of qml and js, this pertains to accessing an Attached Property, which is a qml concept.
– Colin
Nov 10 at 21:56
@eylianesc corrected.
– Colin
Nov 10 at 22:12
|
show 11 more comments
1
what ismyView
?, please provide a Minimal, Complete, and Verifiable example
– eyllanesc
Nov 10 at 18:14
check this answer
– Redanium
Nov 10 at 21:15
@eylianesc correcting.
– Colin
Nov 10 at 21:52
still correcting..@Redanium I have a basic understanding of qml and js, this pertains to accessing an Attached Property, which is a qml concept.
– Colin
Nov 10 at 21:56
@eylianesc corrected.
– Colin
Nov 10 at 22:12
1
1
what is
myView
?, please provide a Minimal, Complete, and Verifiable example– eyllanesc
Nov 10 at 18:14
what is
myView
?, please provide a Minimal, Complete, and Verifiable example– eyllanesc
Nov 10 at 18:14
check this answer
– Redanium
Nov 10 at 21:15
check this answer
– Redanium
Nov 10 at 21:15
@eylianesc correcting.
– Colin
Nov 10 at 21:52
@eylianesc correcting.
– Colin
Nov 10 at 21:52
still correcting..@Redanium I have a basic understanding of qml and js, this pertains to accessing an Attached Property, which is a qml concept.
– Colin
Nov 10 at 21:56
still correcting..@Redanium I have a basic understanding of qml and js, this pertains to accessing an Attached Property, which is a qml concept.
– Colin
Nov 10 at 21:56
@eylianesc corrected.
– Colin
Nov 10 at 22:12
@eylianesc corrected.
– Colin
Nov 10 at 22:12
|
show 11 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Yes and no. The Qt documentation partially addresses this: A Note About Accessing Attached Properties and Signal Handlers
It is not possible to directly access the property from a child. Attached properties need to be explicitly read by the class providing them. For your example, the parent class (StackView
) simply searches for all attached properties it does provide in the child item (FirstView
) as soon as it gets added, and handles all found properties/signals etc. by connecting them internally to whatever logic provides them.
However, nothing prevents you from gettings the attached property from the parent item, as long as you refer to it by id:
sampleProp: view.StackView.someProperty
The thing is: This indirect access only works this way for properties and nor for signals, as you can't simply refer to the attached object via view.StackView
- so sadly, you are stuck with forwarding the signal to the child elements indirectly by creating a second signal in the root item and emitting it when the attached signal gets emitted.
Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
– Colin
Nov 13 at 14:19
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Yes and no. The Qt documentation partially addresses this: A Note About Accessing Attached Properties and Signal Handlers
It is not possible to directly access the property from a child. Attached properties need to be explicitly read by the class providing them. For your example, the parent class (StackView
) simply searches for all attached properties it does provide in the child item (FirstView
) as soon as it gets added, and handles all found properties/signals etc. by connecting them internally to whatever logic provides them.
However, nothing prevents you from gettings the attached property from the parent item, as long as you refer to it by id:
sampleProp: view.StackView.someProperty
The thing is: This indirect access only works this way for properties and nor for signals, as you can't simply refer to the attached object via view.StackView
- so sadly, you are stuck with forwarding the signal to the child elements indirectly by creating a second signal in the root item and emitting it when the attached signal gets emitted.
Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
– Colin
Nov 13 at 14:19
add a comment |
up vote
1
down vote
accepted
Yes and no. The Qt documentation partially addresses this: A Note About Accessing Attached Properties and Signal Handlers
It is not possible to directly access the property from a child. Attached properties need to be explicitly read by the class providing them. For your example, the parent class (StackView
) simply searches for all attached properties it does provide in the child item (FirstView
) as soon as it gets added, and handles all found properties/signals etc. by connecting them internally to whatever logic provides them.
However, nothing prevents you from gettings the attached property from the parent item, as long as you refer to it by id:
sampleProp: view.StackView.someProperty
The thing is: This indirect access only works this way for properties and nor for signals, as you can't simply refer to the attached object via view.StackView
- so sadly, you are stuck with forwarding the signal to the child elements indirectly by creating a second signal in the root item and emitting it when the attached signal gets emitted.
Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
– Colin
Nov 13 at 14:19
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Yes and no. The Qt documentation partially addresses this: A Note About Accessing Attached Properties and Signal Handlers
It is not possible to directly access the property from a child. Attached properties need to be explicitly read by the class providing them. For your example, the parent class (StackView
) simply searches for all attached properties it does provide in the child item (FirstView
) as soon as it gets added, and handles all found properties/signals etc. by connecting them internally to whatever logic provides them.
However, nothing prevents you from gettings the attached property from the parent item, as long as you refer to it by id:
sampleProp: view.StackView.someProperty
The thing is: This indirect access only works this way for properties and nor for signals, as you can't simply refer to the attached object via view.StackView
- so sadly, you are stuck with forwarding the signal to the child elements indirectly by creating a second signal in the root item and emitting it when the attached signal gets emitted.
Yes and no. The Qt documentation partially addresses this: A Note About Accessing Attached Properties and Signal Handlers
It is not possible to directly access the property from a child. Attached properties need to be explicitly read by the class providing them. For your example, the parent class (StackView
) simply searches for all attached properties it does provide in the child item (FirstView
) as soon as it gets added, and handles all found properties/signals etc. by connecting them internally to whatever logic provides them.
However, nothing prevents you from gettings the attached property from the parent item, as long as you refer to it by id:
sampleProp: view.StackView.someProperty
The thing is: This indirect access only works this way for properties and nor for signals, as you can't simply refer to the attached object via view.StackView
- so sadly, you are stuck with forwarding the signal to the child elements indirectly by creating a second signal in the root item and emitting it when the attached signal gets emitted.
edited Nov 11 at 23:42
answered Nov 11 at 23:33
Felix
4,27011636
4,27011636
Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
– Colin
Nov 13 at 14:19
add a comment |
Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
– Colin
Nov 13 at 14:19
Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
– Colin
Nov 13 at 14:19
Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
– Colin
Nov 13 at 14:19
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241975%2fqt-qml-accessing-attached-property-from-another-qml-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
what is
myView
?, please provide a Minimal, Complete, and Verifiable example– eyllanesc
Nov 10 at 18:14
check this answer
– Redanium
Nov 10 at 21:15
@eylianesc correcting.
– Colin
Nov 10 at 21:52
still correcting..@Redanium I have a basic understanding of qml and js, this pertains to accessing an Attached Property, which is a qml concept.
– Colin
Nov 10 at 21:56
@eylianesc corrected.
– Colin
Nov 10 at 22:12