accessing Component from multiple other Components
-
Hi all -
I have a Component:
Component { id: activitySelector ScheduleActivitySelector { // in ScheduleActivitySelector.qml onSaveClicked: (activity) => { if (activity) { // do some stuff } } }I need to push this component onto a StackView from multiple other Components that I've defined. How do I do this?
Thanks...
-
@Bob64 said in accessing Component from multiple other Components:
is it the same instance that you need to access, or do you need to instantiate it multiple times for each of the client components?
I think it can be the same instance. There never will be a case when both clients are active at the same time.
I did a little more reading, and found that this helps:
var scheduleActivitySelector = Qt.createComponent("ScheduleActivitySelector.qml") if (scheduleActivitySelector.status === Component.Ready) { scheduleSideDrawerStackView.push(scheduleActivitySelector) }Now I have to figure out how to connect to a signal from the Component.
EDIT:
I tried this:
ColumnLayout { property var scheduleActivitySelector: Qt.createComponent("ScheduleActivitySelector.qml") Button { onClicked: { scheduleSideDrawer.open() // scheduleActivitySelector = Qt.createComponent("ScheduleActivitySelector.qml") if (scheduleActivitySelector.status === Component.Ready) { scheduleSideDrawerStackView.push(scheduleActivitySelector) } } Connections { target: scheduleActivitySelector function onSaveClicked (activity) { // do stuff } } }But I get a run-time error:
QML Connections: Detected function "onSaveClicked" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.The signal is definitely in my component; any ideas what I'm doing wrong here?
Thanks...
@mzimmers
Qt.createComponentretuns a Component and not an actual object instance.Alternatively StackView.push can take an url so you can just do
scheduleSideDrawerStackView.push("ScheduleActivitySelector.qml")StackView.push returns the item created, you can use that as the target of your
Connections -
Hi all -
I have a Component:
Component { id: activitySelector ScheduleActivitySelector { // in ScheduleActivitySelector.qml onSaveClicked: (activity) => { if (activity) { // do some stuff } } }I need to push this component onto a StackView from multiple other Components that I've defined. How do I do this?
Thanks...
Better you define this on different qml file as external component & access it from everywhere.
-
Better you define this on different qml file as external component & access it from everywhere.
@dheerendra how do I code that? I tried this:
scheduleSideDrawerStackView.push(ScheduleActivitySelector)but that produces this error:
QML StackView: push: nothing to push -
@dheerendra how do I code that? I tried this:
scheduleSideDrawerStackView.push(ScheduleActivitySelector)but that produces this error:
QML StackView: push: nothing to push@mzimmers is it the same instance that you need to access, or do you need to instantiate it multiple times for each of the client components?
(The error you mentioned there is that you are pushing the name of the component and not the id of an instance of the component.)
-
@mzimmers is it the same instance that you need to access, or do you need to instantiate it multiple times for each of the client components?
(The error you mentioned there is that you are pushing the name of the component and not the id of an instance of the component.)
@Bob64 said in accessing Component from multiple other Components:
is it the same instance that you need to access, or do you need to instantiate it multiple times for each of the client components?
I think it can be the same instance. There never will be a case when both clients are active at the same time.
I did a little more reading, and found that this helps:
var scheduleActivitySelector = Qt.createComponent("ScheduleActivitySelector.qml") if (scheduleActivitySelector.status === Component.Ready) { scheduleSideDrawerStackView.push(scheduleActivitySelector) }Now I have to figure out how to connect to a signal from the Component.
EDIT:
I tried this:
ColumnLayout { property var scheduleActivitySelector: Qt.createComponent("ScheduleActivitySelector.qml") Button { onClicked: { scheduleSideDrawer.open() // scheduleActivitySelector = Qt.createComponent("ScheduleActivitySelector.qml") if (scheduleActivitySelector.status === Component.Ready) { scheduleSideDrawerStackView.push(scheduleActivitySelector) } } Connections { target: scheduleActivitySelector function onSaveClicked (activity) { // do stuff } } }But I get a run-time error:
QML Connections: Detected function "onSaveClicked" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.The signal is definitely in my component; any ideas what I'm doing wrong here?
Thanks...
-
@Bob64 said in accessing Component from multiple other Components:
is it the same instance that you need to access, or do you need to instantiate it multiple times for each of the client components?
I think it can be the same instance. There never will be a case when both clients are active at the same time.
I did a little more reading, and found that this helps:
var scheduleActivitySelector = Qt.createComponent("ScheduleActivitySelector.qml") if (scheduleActivitySelector.status === Component.Ready) { scheduleSideDrawerStackView.push(scheduleActivitySelector) }Now I have to figure out how to connect to a signal from the Component.
EDIT:
I tried this:
ColumnLayout { property var scheduleActivitySelector: Qt.createComponent("ScheduleActivitySelector.qml") Button { onClicked: { scheduleSideDrawer.open() // scheduleActivitySelector = Qt.createComponent("ScheduleActivitySelector.qml") if (scheduleActivitySelector.status === Component.Ready) { scheduleSideDrawerStackView.push(scheduleActivitySelector) } } Connections { target: scheduleActivitySelector function onSaveClicked (activity) { // do stuff } } }But I get a run-time error:
QML Connections: Detected function "onSaveClicked" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name.The signal is definitely in my component; any ideas what I'm doing wrong here?
Thanks...
@mzimmers
Qt.createComponentretuns a Component and not an actual object instance.Alternatively StackView.push can take an url so you can just do
scheduleSideDrawerStackView.push("ScheduleActivitySelector.qml")StackView.push returns the item created, you can use that as the target of your
Connections -
@mzimmers
Qt.createComponentretuns a Component and not an actual object instance.Alternatively StackView.push can take an url so you can just do
scheduleSideDrawerStackView.push("ScheduleActivitySelector.qml")StackView.push returns the item created, you can use that as the target of your
Connections -
M mzimmers has marked this topic as solved on