We have moved to a new Sailfish OS Forum. Please start new discussions there.
1

Variables from other .qml files [answered]

asked 2016-01-03 18:35:12 +0300

ApB gravatar image

This has got me stuck beyond anything else this far in QML and need help cause i cant get it to work.

We have a main page containing a list and a function that fills the list -populatelist()- with stuff in a database. We also have a page (dialog to be precise) to edit the list items. In order to get the edit dialog to work i have to stop the function that fills the list items. The code is like this:

Mainpage

Page {
    id: page

    property bool stopthis: false

    Component.onCompleted: {

        DBase.inDBase();

    }
    onStatusChanged: {

        console.log("status changed")
        if (!stopthis) {
            populateList()
        }

    }

    SilicaListView {
        id:connectionsList
        anchors.fill: parent
        model:listModel


            delegate: ListItem {
                        id: listItem
                        menu: contextMenuComponent
                        onClicked: {

                        }

                            }
                            Component {
                                id: contextMenuComponent
                                ContextMenu {

                                    MenuItem {
                                        text: qsTr("Edit")
                                        onClicked: {
                                            console.log("going to edit", model.username)
                                            page.stopthis = true
                                            var test = pageStack.push(Qt.resolvedUrl("EditCon.qml"), {"modelID": model})
                                            test.accepted.connect(function() {page.stopthis = test.theh})
                                        }

    }

    ListModel {
        id: listModel

And the Editpage:

Dialog {
    id: editdialog

    property var modelID
    property bool theh

//FIX me Add commands Check.
    canAccept: connectionnameField.text != modelID.connection_name 
    acceptDestinationAction: PageStackAction.Pop

    onDone:{
        DBase.update(...)
        editdialog.theh = false
        console.log("edited connection")
    }

However the variable page.stopthis doesn't get the value of test.theh. The variable test.theh is returned correctly from the dialog page -console log proves that- but test.accepted.connect seems to not be able to do anything with the main page variables. I tried calling a function from it to set the variable but this didn't work either. Tried also other stuff that were proposed by coderus and kimoli on the IRC but none worked. The documentation here does it in the same(?) way that i try to do it in my code but in my case it doesn't work.

So any help will be greatly appreciated. Thanks in advance.

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, an answer was accepted" by ApB
close date 2016-01-03 19:22:17.598920

2 Answers

Sort by » oldest newest most voted
1

answered 2016-01-03 18:54:12 +0300

Hello, Why don't use the status final value to test if this is the visible page ?

onStatusChanged: {
      console.log("status changed")
      if (status == PageStatus.Active) {
             populateList()
      }    
}
edit flag offensive delete publish link more

Comments

because i had no idea this existed. will test and report back.

ApB ( 2016-01-03 19:17:50 +0300 )edit

Worked like a motherfucking charm. You get a cookie a cheezeburger and an internet. :D

Thanks a million.

ApB ( 2016-01-03 19:21:49 +0300 )edit

@LouJo in case you want artwork related help in any of your apps (icons UI etc) just ask. I owe you one ;).

ApB ( 2016-01-03 19:36:46 +0300 )edit
0

answered 2016-01-03 19:25:41 +0300

kimmoli gravatar image

updated 2016-01-03 19:26:05 +0300

Put the contextmenu onClicked: stuff in its own function under ListItem

ListItem {
  function menuEditClicked() { ... }
.
.
MenuItem {
    onClicked: menuEditClicked()
edit flag offensive delete publish link more

Question tools

Follow
1 follower

Stats

Asked: 2016-01-03 18:35:12 +0300

Seen: 889 times

Last updated: Jan 03 '16