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. Data file

Data file

Scheduled Pinned Locked Moved QML and Qt Quick
14 Posts 5 Posters 4.3k Views
  • 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.
  • Q Offline
    Q Offline
    qxoz
    wrote on last edited by
    #2

    Do you need pure qml solution?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Ankit.k
      wrote on last edited by
      #3

      Yes. I would be developing it in QML.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        chrisadams
        wrote on last edited by
        #4

        QtQuick 2? Use the QtQuick.LocalStorage singleton type.

        Cheers,
        Chris.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Ankit.k
          wrote on last edited by
          #5

          I m currently using QtQuick 1.1. Isn't there something similar in it?

          1 Reply Last reply
          0
          • F Offline
            F Offline
            favoritas37
            wrote on last edited by
            #6

            Of course there is. Offline local storage using MySQL. Grab to following code and add it to a javascript file.

            storage.js
            @
            //
            /
            Key Value store (mostly used for settings storage) /
            /
            /

            /** Set value to storage */
            function setKeyValue(key, value) {
            var db = openDatabaseSync("YOUR_APP_NAME", "1.0", "Description", 10);

            db.transaction(function(tx) {
                               tx.executeSql('CREATE TABLE IF NOT EXISTS ' +
                                             'KeyValueStorage(keyName TEXT, textValue TEXT)');
                               var rs = tx.executeSql("SELECT textValue FROM KeyValueStorage WHERE keyName = \"" + key + "\"");
                               var sql = "";
                               if(rs.rows.length>0) {
                                   sql = "UPDATE KeyValueStorage SET textValue = \"" + value + "\" WHERE keyName = \"" + key + "\"";
                               } else {
                                   sql = "INSERT INTO KeyValueStorage(textValue, keyName) VALUES (\"" + value + "\",\"" + key + "\")";
                               }
                               tx.executeSql(sql);
                           });
            

            }

            /** Get value from storage */
            function getKeyValue(key) {
            var value;
            var db = openDatabaseSync("YOUR_APP_NAME", "1.0", "Description", 10);
            db.transaction(function(tx) {
            tx.executeSql('CREATE TABLE IF NOT EXISTS KeyValueStorage(keyName TEXT, textValue TEXT)');
            var result = "";
            var rs = tx.executeSql("SELECT textValue FROM KeyValueStorage WHERE keyName = "" + key + """);
            for (var i = 0; i < rs.rows.length; i++) {
            result = rs.rows.item(i).textValue;
            value = result;
            //console.log("---, " + value);
            }
            if(rs.rows.length===0) {
            value = "0";
            //console.log("---, " + value);
            }
            });
            return value;
            }
            @

            So this is a simple singleton key-value storage. To use it in a qml file just write the following:

            @
            import QtQuick 1.1
            import "storage.js" as Storage

            ...
            Storage.setKeyValue("ip", "0.0.0.0");
            ...
            @

            Regards.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Ankit.k
              wrote on last edited by
              #7

              Thanks a lot. I tried it, but where is the file location. I could not find

              1 Reply Last reply
              0
              • A Offline
                A Offline
                Ankit.k
                wrote on last edited by
                #8

                I managed to get a file using a Qfile. Now I want to connect the value entered by the user in the qml file to a variable whose value can be stored in the file through C++.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  favoritas37
                  wrote on last edited by
                  #9

                  Wait a minute, what do you mean "where is the file location" ?

                  Why do you care where is the file stored since the functionality is working and you are either way going to access it only through your program?

                  Any way, to answer your question, there is a MySQL file created in the executable's folder in binary format that holds the data of the local database that gets created when using the code that i posted above.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tzander
                    wrote on last edited by
                    #10

                    When you write you wanted a binary file, that implies to me, and I think favoritas37 that you do not ever want to use it as a document that you can email a friend.
                    The only time you want to store something in binary form is when you just want to use it to remember the data between times you run the app.

                    So thats why the mysql answer was given, its a simple and effective way to do it :)

                    If your needs are different than that, please explain, maybe there is a better solution!

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      favoritas37
                      wrote on last edited by
                      #11

                      Hello Thomas,

                      indeed this is what i wanted to say.

                      Thank you :)

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Ankit.k
                        wrote on last edited by
                        #12

                        Hi favoritas37
                        I just wanted to check whether the code was working properly or not. Thanks for your help

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          Ankit.k
                          wrote on last edited by
                          #13

                          I would be running this app on embedded platform eventually, so will the java code make it slow

                          1 Reply Last reply
                          0
                          • T Offline
                            T Offline
                            tzander
                            wrote on last edited by
                            #14

                            Qt and/or QML is not using Java.

                            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