@qtprogrammer123 said in Action-s in separete file:
Hi,
I'm trying place actions is separete file Act.qml, after that i add Act{ id: actions} in main.qml, but they dont work.
Hi,
It's helpful to have a description of what not working means. A compiler or interpreter error message, a screen capture, or something to differentiate the expected from the actual outcome.
Act.qml
Item {
...
Action {
id: copy
}
}
main.qml:
Act {
id: act
}
Menu {
id: men
MenuItem {
text: "copy"
id: menuItem
action: act.copy
}
//rest of actions
}
I may be leaping to conclusions, but it looks like this is attempting to use an id from Act.qml in main.qml. That won't work. The id property of items should only used within the same file.
The cleanest solution is to export each of the actions as a property of Act.qml. Eg
Act.qml:
Item {
property Action copy: Action {
text: qsTr("&Copy")
}
property Action paste: Action {
text: qsTr("&Paste")
}
}
main.qml:
Window {
Act { id: act }
MenuItem {
action: act.copy
}
}
It's also possible to access children of a top level item via the children, data, or resources properties of an Item. Finding a particular instance using these tends to require more code and more effort to maintain. They are useful for handling all children.