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. Intagrating SQLite with Qt Quick
Qt 6.11 is out! See what's new in the release blog

Intagrating SQLite with Qt Quick

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 2.8k 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.
  • D Offline
    D Offline
    dstudentx
    wrote on last edited by
    #1

    I'm trying to include a SQLite database with QT Quick but I can't find any examples.

    Does anyone know of any example programs I can play with?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luoqiya
      wrote on last edited by
      #2

      There is example in yourInstall\Qt5.0.2\5.0.2\mingw47_32\examples\declarative\sqllocalstorage

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dstudentx
        wrote on last edited by
        #3

        Thanks but I need it to be non c++

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

          https://qt.gitorious.org/qt/qtdeclarative/blobs/stable/examples/quick/localstorage/localstorage/hello.qml

          Cheers,
          Chris.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dstudentx
            wrote on last edited by
            #5

            Thanks that helped me loads!
            I have a question the is related to the link you sent me; I posted it on stackoverflow but never got a response.

            in qtquick 2.0 I can read text from a database but I can't get it to show in in a specific state only in all states. how can I call my function reading in the database in a specific state for example 'state1'

            @Text {
            text: "?"
            anchors.horizontalCenter: parent.horizontalCenter
            function get_db() {
            var db = LocalStorage.openDatabaseSync("DB1", "1.0", "The Example QML SQL!", 1000000);
            db.transaction(
            function(tx) {
            tx.executeSql('CREATE TABLE IF NOT EXISTS Greeting(salutation TEXT, salutee TEXT)');
            for ( var z=0; z<10; z++){
            // tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ z, z ]);
            }
            // tx.executeSql('INSERT INTO Greeting VALUES(?, ?)', [ 'hello', 'world' ]);
            var rs = tx.executeSql('SELECT * FROM Greeting');
            var r = ""
            for(var i = 0; i < rs.rows.length; i++) {
            r += rs.rows.item(i).salutation + ", " + rs.rows.item(i).salutee + "\n"
            }
            text = r
            })}
            Component.onCompleted: get_db()
            }

            states: [

            State {
                name: "State1"
                PropertyChanges {
                    target: mousearea1
                    x: 608
                    y: 1022
                }
            
                PropertyChanges {
                    target: image5
                    x: 760
                    y: 980
                }
            
                PropertyChanges {
                    target: image1
                    x: 245
                    y: 345
                    width: 298
                    height: 271
                    fillMode: "PreserveAspectFit"
                    source: "images/item.png"
                    opacity: 1
            
                }
            
                PropertyChanges {
                    target: mousearea2
                    width: 130
                    height: 190
                    opacity: 1
                      onClicked: page.state = 'base state'
                }
            
                PropertyChanges {
                    target: image2
                    x: 543
                    y: 345
                    width: 154
                    height: 271
                    fillMode: "PreserveAspectFit"
                    source: "images/item.png"
                    opacity: 1
                }
            }
            

            ]@

            1 Reply Last reply
            0
            • L Offline
              L Offline
              luoqiya
              wrote on last edited by
              #6

              @Component.onComplated{
              get_db();
              Test_id.state:"State1"
              }@
              u should set when to change your state.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dstudentx
                wrote on last edited by
                #7

                Thanks for the help!
                I getting a syntax error though.

                !http://farm9.staticflickr.com/8545/8938019077_5c2dccb53c_o.jpg(image)!

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  luoqiya
                  wrote on last edited by
                  #8

                  Sorry for the lately reply.
                  You should set your parent item id to Test_id

                  Like this:

                  @
                  Rectangle{
                  id:"test_id"
                  ...
                  Component.onComplated{
                  test_id.state="your state"
                  }
                  }
                  @

                  in your demo,you should change Test_id.state="State1" to mouseArea1.state="State1"

                  read QML states manual u may understand it

                  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