Communication within qml files using signals and slots



  • Hi

    I have two qml files naming Upcoming.qml, New_departure.qml, New_departureForm.ui.qml. I need to communicate between the Upcoming.qml and New_departure.qml. I have used the dynamic objects for the creation for communication and the code is working fine to get the mouse values of the upcoming.qml but the upcoming and new_departure qmls are overlapping witheach other my code is as follows

    Upcoming.qml

    Item {
        id:upcoming_days_Delegate
        property var ambObj: null
        signal xy(var x);
        property var ambObj1: null
        MouseArea{
            id:mousearea;width:44;height:80;x:185;y:0;
            onReleased: {
                var component = Qt.createComponent("New_departure_time.qml");
                if (component.status === Component.Ready)
                    ambObj = component.createObject(window_mode)
                ambObj.anchors.fill=window_mode;
                var component_1 = Qt.createComponent("Clicked_image.qml");
                if (component_1.status === Component.Ready)
                    ambObj1 = component_1.createObject(item_highlight)
                ambObj1.x=mouse.x+162;ambObj1.y=15;
                xy(mouse.x+162);
                console.log("Enter Sending")
                ambObj.close.connect( function(a) { ambObj.destroy(); ambObj1.destroy() } );
            }
        }
    }
    

    new_departure.qml

    Item {
        signal close(string cl);
        property var cmbObj: null
        id: new_departure_time_item;
    
        Info_popup {
            id: info_popup_item;
        }
        Select_date {
            id: select_date_item;
        }
        Charging_popup {
            id: charging_item;
        }
        Notification_bar { 
            id: notify_bar;
            visible: false;
            x: 298;
            y: 0;
        }
        Component.onCompleted: {
            var component = Qt.createComponent("Upcoming_days.qml");
            if (component.status === Component.Ready)
                cmbObj = component.createObject(new_departure_time_item);
            cmbObj.xy.connect( function (a) { console.log(a) } )
        }
    }
    

    [Edit: Added code tags -- @Wieland]


Log in to reply
 

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