×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Passing data between QML pages/files?

    Hi all,

    I am looking for some beginners advice here.

    I have a number of lists being presented to the user. Each list is built from an xml feed using xmlListModel and listView, and each list is on a separate QML page. So, when the user makes a selection from the first list, her selection should be available to the code on Page2.qml where it will be used to build the next list (e.g. If I click ''fruits'', the next page is going to load fruits.xml to build a listView).

    My problem is that I can't seem to pass the information associated with a selection to the next page. How can I access the data associated with my first listModel?

    (as an aside, links to third party tutorials that you think might help are appreciated)

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Passing data between QML pages/files?

    it will be great if you tell us the ways you tried.

    The simplest approach would be to have signal with a parameter as the selected content from the model, on clicking any item on the listview you can fire the signal with the selected item.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Re: Passing data between QML pages/files?

    I have gotten as far as getting the data I want to my MouseArea element, but don't know how to send it any further. Keep in mind I started learning QML this week... lots of reading.

    Here's a simplification of my code, assume the rectangles/mouseareas are properly drawn. I have the onClicked signal where I have been able to print the data I'm after to my console and switch the page.

    Code:
     XmlListModel {
            id: routeList
    		source: ...
    		XmlRole { name: "title"; query: "@title/string ()" }
        }
    
        ListView {
            id: routeSelect
            model: routeList
    
            delegate: Item {
    	    property variant routeData: model
    
    	    id: delegate
                Rectangle {
    			id: wrapper
    				Text {
    					id: routeName
    					text: title
    					}
                        MouseArea {
                            onClicked: {
    				routeSelect.currentIndex = index
    				console.log(routeSelect.currentItem.routeData.title) //the xml role "title" is coming through successfully
    				pageStack.push(Qt.resolvedUrl("Page2.qml"))
    				}
                            }
    		}
    
            }
        }
    }
    Essentially, what I would like to do is access "routeSelect.currentItem.routeData.title" from Page2.qml, which is currently unable to find the variable.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Passing data between QML pages/files?

    actually this can be a wrong approach in navigation this is what is see.

    You might have a stack where you might have declared your pages correct??

    First what you can do is declare a property and a signal in your Page1.qml like:

    Code:
          property string listitemString 
          signal listItemClicked()
    now in the mouseArea what you can do is:

    Code:
    page1.listItemString =  routeSelect.currentItem.routeData.title
    page1.listItemClicked()
    We are assigning the value of currentItem data in listItemData Property which you can use later.
    and then listItemClicked() is emitted.

    in your pageStack.qml

    Code:
    Page1{
    onListItemClicked{
       page1. listItemData // you have you title here
      // push page2.qml here and do whatever you want to do with the title
    }
    }
    I hope its now much clear to you.

Similar Threads

  1. Need help with passing data between threads
    By sudeepa2005 in forum Symbian
    Replies: 3
    Last Post: 2009-05-26, 07:07
  2. data passing between many views
    By Vymmiatacz in forum Symbian User Interface
    Replies: 5
    Last Post: 2008-11-15, 18:46
  3. Passing a TDesC between views
    By ViruDoshi in forum Symbian User Interface
    Replies: 6
    Last Post: 2005-12-20, 14:48
  4. Passing data between two views
    By vcribe in forum Symbian User Interface
    Replies: 3
    Last Post: 2005-01-31, 06:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×