Access Tabview button from main



  • hi!

    i have this form:

    Item {
        width: 900
        height: 900
        id: root
    
        TabView {
            id: tabView
            width: 900
            height: 900
    
            Tab {
                id: tabClienti
                title: "Clienti"
                source: "Clienti.qml"
    
                Rectangle {
                    id: rectangleClienti
                    x: 0
                    y: 32
                    width: 900
                    height: 69
                    color: "#ffffff"
    
                    TextField {
                        id: textNpu
                        x: 8
                        y: 22
                        width: 164
                        height: 26
                        placeholderText: qsTr("NPU")
                    }
    
                    Button {
                        id: btnClienti
                        x: 807
                        y: 21
                        text: qsTr("Cerca")
                    }
                }
            }
    }
    
    

    i'd need access to button from my main.qml:

    ApplicationWindow {
        visible: true
        width: 900
        height: 900
        minimumWidth: 900
        minimumHeight: 900
        maximumWidth: 900
        maximumHeight: 900
        title: qsTr("Cimoda Admin")
    
        menuBar: MenuBar {
            Menu {
                title: qsTr("File")
                MenuItem {
                    text: qsTr("&Open")
                    onTriggered: console.log("Open action triggered");
                }
                MenuItem {
                    text: qsTr("Exit")
                    shortcut: "Ctrl+Q"
                    onTriggered: Qt.quit();
                }
            }
        }
    
        MainForm {
            anchors.fill: parent
            // ACCESS TO BUTTON
        }
    }
    

    how can i do this operation in qml??


  • Lifetime Qt Champion

    Hi,

    Why do you need to access that button from your ApplicationWindow ?



  • @SGaist

    hi!

    to set the onCliecked event.
    if i do simething like this:

                    Button {
                        id: btnClienti
                        x: 807
                        y: 21
                        text: qsTr("Cerca")
                        onClicked: messageDialog.show("hello")
                    }
    

    qtcreator tell me this message:

    Functions are not supported in a Qt Quick UI Form
    

  • Lifetime Qt Champion

    It's not the role of your ApplicationWindow to know that there's a specific button in a sub-control from another control that you want do react on.

    You should rather emit a signal from that form that you will react on in ApplicationWindow. That way you'll avoid tight coupling and maintenance nightmare. Just imagine that you change that button for something else, now you have to modify at least two files to make things work again.



  • something like this?

    Item {
        width: 900
        height: 900
        id: root
    
        signal searchClient(string msg)
    
        TabView {
            id: tv
            width: 900
            height: 900
    
            Tab {
                id: tabClienti
                title: "Clienti"
                source: "Clienti.qml"
    
                Rectangle {
                    id: rectangleClienti
                    x: 0
                    y: 32
                    width: 900
                    height: 69
                    color: "#ffffff"
    
                    TextField {
                        id: textNpu
                        x: 8
                        y: 22
                        width: 164
                        height: 26
                        placeholderText: qsTr("NPU")
                    }
    
                    Button {
                        id: btnClienti
                        x: 807
                        y: 21
                        text: qsTr("Cerca")
                        onClicked: root.searchClient("HELLO")
                    }
                }
            }
        }
    
    }
    

    but i have always this message:

    Functions are not supported in a Qt Quick UI Form
    

    and the designer doesn't work properly!



  • ok, this seems to work:

            Button {
                id: btnClienti
                x: 800
                y: 21
                text: qsTr("Cerca")
                onClicked: {
                    console.log('OK')
                }
            }
    

Log in to reply
 

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