QtQuick Action in C++ (or at least a separate .qml file)



  • When I deploy my app, I want the users to be able to customise the GUI, but not change/break the functionality. Is it possible to create QtQuick Action objects in C++?

    I've tried using QAction, but that didn't work.

    I've seen QQmlAction come up when googling, but it looks like it is from the QtControls internals.

    Can this be done.

    My 2nd idea is to hide the Action objects from the user so they don't accidentally change them. Is it possible to move Action objects into a separate .qml file and connect them up to menus, toolbars, etc

    Thanks,
    Frank



  • 2nd option is definitely possible. Define actions in different file with Ids. Use this ids to associate.

    First option is doubtful.



  • How do I define more than one action in a single file? There can only be one root object? What can i use for a container?



  • I've tried a few things. The simplest was to define the Action object in it's own file...

    ActionOpenGCode.qml
    @
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Layouts 1.1
    import QtQuick.Dialogs 1.1
    import nexis 1.0

    Action {
    text: "&Open"
    shortcut: StandardKey.Open
    iconSource: "../images/tool_open.gif"
    tooltip: "Open a G-Code File"
    }
    @

    And then in main.qml
    @
    ActionOpenGCode {
    id: actionOpenGCode
    }

    menuBar: MenuBar {
        Menu {
            title: "&File"
            MenuItem { action: actionOpenGcode }
    

    @

    I get the error...

    file:///home/frankt/svn/nexis/nexis/qml/main.qml:226: ReferenceError: actionOpenGcode is not defined (which is line 8 of the main.qml snippet)

    Am I doing this right?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.