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).










share|improve this question



















  • 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














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).










share|improve this question



















  • 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












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).










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 22:25









eyllanesc

67.6k82952




67.6k82952










asked Nov 10 at 18:12









Colin

1,5421926




1,5421926







  • 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












  • 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







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












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.






share|improve this answer






















  • Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
    – Colin
    Nov 13 at 14:19










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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

























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.






share|improve this answer






















  • Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
    – Colin
    Nov 13 at 14:19














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.






share|improve this answer






















  • Okay, yes that's it. The details of scope in qml are quite complex. Thank you.
    – Colin
    Nov 13 at 14:19












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.






share|improve this answer














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.







share|improve this answer














share|improve this answer



share|improve this answer








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
















  • 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

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線