Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] How to share variables between different pages ?

[SOLVED] How to share variables between different pages ?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 4 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    barmeier
    wrote on last edited by
    #1

    Hi,

    I retrieve a lot of data via a XmlHttpRequest from a server. I would like to present the data in different pages.

    Could someone give me a hint ?

    Thanks.

    Ciao
    Matze

    1 Reply Last reply
    0
    • I Offline
      I Offline
      interface_johnson
      wrote on last edited by
      #2

      I think you can store your data in a C++ object, make it accessible from your QML page, call a method on this object in your qml, and that method in your C++ code can load the data into the target QML page .... please consider QAbstractItemModel and have look at http://doc.qt.nokia.com/4.7/qdeclarativemodels.html for examples, cheers.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        barmeier
        wrote on last edited by
        #3

        Hi,
        thanks for the reply, but I am unexperienced in using C++.
        Do you think this is the only possibility to share data across pages ?

        That would be bad.

        Any other suggestions ?

        Ciao
        Matze

        1 Reply Last reply
        0
        • T Offline
          T Offline
          task_struct
          wrote on last edited by
          #4

          Hi,

          add a property to your PageStack and than you can access this property from pages by using
          @
          pageName.pageStack.yourPropertyName
          @

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • S Offline
            S Offline
            srikanth_trulyit
            wrote on last edited by
            #5

            I suggest not to talk with other page directly because this introduces unwanted coupling with pages. Share the data using setter and getter methods via javascript. Make sure it is a defined with .pragma library so that this JS is always shared.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              barmeier
              wrote on last edited by
              #6

              Hi,

              thanks for your help !

              I found this in the wiki (shame on me)

              http://www.developer.nokia.com/Community/Wiki/Defining_global_variable_in_QML

              I think this is what srikanthsombhatla means. The hard page coupling should be no problem for me, but I want to share a JS array. It looks easier for me to try the JS-lib-thing.

              Thanks a lot !

              Ciao
              Matze

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved