Cannot access QML element

420 views Asked by At

I am trying to write simple application for sailfish OS, but I got in trouble with interaction with cover. Cover is a simple QML component that appeared at home screen when my app is hidden. There is a code how app initialized:

ApplicationWindow
{
    Translator {
        id: translator
        Component.onCompleted: translator.translate("ru")
    }

    initialPage: Component { Menu { id:pageMenu } }
    cover: Component { CoverPage {id: myCoverPage } }
}

CoverPage is a qml file that consist of

import QtQuick 2.0
import Sailfish.Silica 1.0

CoverBackground {
    CoverPlaceholder {
        id: placeHolder
        text: pageMenu.testprop            // line 38
        Component.onCompleted: {
            console.log("Component.onCompleted placeHolder")
        }
    }
}

The problem is that I cannot access to any elements at cover page from any part of my code outside that file (CoverPage.qml) For example, in that case I got that error:

[D] onCompleted:11 - Component.onCompleted pageMenu
[D] onCompleted:40 - Component.onCompleted placeHolder
[W] unknown:38 - file:///usr/share/bashReaderOnlyQML/qml/pages/CoverPage.qml:38: ReferenceError: pageMenu is not defined

But pageMenu is defined in another file which was loaded from ApplicationWindow.initialPage property and as you can see from log successfully initialized. I tried to find some examples at Github, but without result

1

There are 1 answers

0
marmistrz On BEST ANSWER

I guess you should expose pageMenu as a global alias, e.g. property alias pageMenu_global as a direct child of ApplicationWindow and make it point to pageMenu