1

I have 2 QML Silica Pages, Main.qml and Icon.qml.
Main.qml has this distribution:

import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3

Page {
    SilicaFlickable {
        id: mainList
        
        Button {
            text: "Stack the next page"
            onClicked: { // Stack de Icon Page
                pageStack.push(Qt.resolvedUrl("Icon.qml"))
            }
        }
        function reload(){ }
        Python {
           id: py
           Component.onCompleted: { mainList.reload() }
        }
    }
}

And I want to call the function reload() since Icon:

import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3

Page {
    id: iconEditor

    Button {
        onClicked: {
            pageStack.pop()
            pageStack.completeAnimation()
            pageStack.currentPage.mainList.reload() // Fail
        }
    }
}

The Main.qml Page is stacked in the principal QML file like this:

import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3

ApplicationWindow {
    id: root
    Python {
        Component.onCompleted: {
            pageStack.push(Qt.resolvedUrl("Main.qml"))
        }
    }
}

How can I call the function on the previous page of the stack?

kirbylife
  • 115
  • 1
  • 9
  • please provide a [mre] – eyllanesc May 16 '21 at 19:42
  • @eyllanesc the most minimal example I could think of was the one I put in the question, but if you want to see the complete example here is the link to [git folder](https://gitlab.com/kirbylife/harbour-muchkin/-/tree/master/qml) – kirbylife May 16 '21 at 20:02
  • 1) The MRE should not depend on an external resource, 2) The MRE has 2 characteristics: minimal and reproducible, but in your case it does not meet the second, so you will have to work an MRE and publish it in your post if you want help. Please read [ask] and review the [tour] – eyllanesc May 16 '21 at 20:04
  • @eyllanesc Already edit the question to add a more clearer MRE – kirbylife May 16 '21 at 20:18
  • what is `pageStack`? that code is not an MRE. If you want to check that your code is an MRE then do the following: create a new folder, copy the code from your post (without modifying it) in the necessary files and run the application. If you get the same error then it is most likely an MRE. – eyllanesc May 16 '21 at 20:20
  • @eyllanesc PageStack is a feature of Silica library [link](https://sailfishos.org/develop/docs/silica/qml-sailfishsilica-sailfish-silica-pagestack.html/) I don't write PageStack, for that I import the Silica library. – kirbylife May 16 '21 at 20:23
  • Now with the imports it can already be an MRE, I'm going to test it and let you know. – eyllanesc May 16 '21 at 20:25
  • 1
    try add `property alias mainList: mainList` before `SilicaFlickable {`. – eyllanesc May 16 '21 at 20:35

1 Answers1

1

The "id" have as scope only the .qml where it was defined and cannot (or should be used outside of that scope). If you want to expose objects or variables then you must do it by creating a property in the toplevel of the file.

In this case a solution is to use an alias property:

import QtQuick 2.0
import Sailfish.Silica 1.0
import io.thp.pyotherside 1.3

Page {
    property alias mainList: mainList

    SilicaFlickable {
        id: mainList
        // ...
eyllanesc
  • 235,170
  • 19
  • 170
  • 241