Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML: aliases to children properties

I created dialog and trying to add some aliases to change it title and text:

import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.Popups 0.1

Item {
    signal confirmed;
    signal canceled;

    property alias title: dialog.title
    property alias text: dialog.text

    signal show(variant caller);

    Component {
         id: dialogComponent

         Dialog {
             id: dialog
             title: "Exit Game"
             text: "Are you sure that you want to exit?"

             Button {
                 text: "cancel"
                 onClicked:
                 {
                     canceled();
                     PopupUtils.close(dialog);
                 }
             }

             Button {
                 text: "confirm"
                 color: "orange"
                 onClicked:
                 {
                     confirmed();
                     PopupUtils.close(dialog);
                 }
             }
         }
    }

    onShow:
    {
        PopupUtils.open(dialogComponent, caller)
    }
}

But I has problem:

qrc:/ConfirmationDialog.qml:8:23: Invalid alias reference. Unable to find id "dialog"

So, how to create this aliases? Why Item don't see it? What is the best way to change this properties?

Best regards, Nick

like image 324
Robotex Avatar asked Oct 04 '22 10:10

Robotex


2 Answers

Dialog object won't be available until u have instantiated it, since it's inside a component.

You can refer it's id, if it is not in the component.

like image 144
Mahesh Avatar answered Oct 13 '22 12:10

Mahesh


That's because of the Component QML element. Simply make the Dialog a top-level item in your .qml file and treat that as a component for dynamic instantiations.

like image 44
Jan Kundrát Avatar answered Oct 13 '22 10:10

Jan Kundrát