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. Location of SQLite database

Location of SQLite database

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 3 Posters 2.4k 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.
  • J Offline
    J Offline
    JasonS
    wrote on last edited by
    #1

    Is there a way to specify the SQLite database that LocalStorage.openDatabaseSync uses? There is a way to specify the offline storage path, QQmlEngine::offlineStoragePath(), but don't see how to set the file name of the database.

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      I don't think anything exist like this. We tried earlier and did not go anywhere. Enjoy the same.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      4
      • J Offline
        J Offline
        JasonS
        wrote on last edited by
        #3

        Essentially I need to use SQL as a conduit between Python and QML. I want to be able to write temperature data to a previously created SQL database from a loop on a timer in Python and then display the same data in my QML app? My QML app has multiple screens and this data would only be displayed when a specific screen is visible. Other QML screens will have an interface to write data to the SQL database and then be read and used in Python. Do you have any suggestions on what I could try and use? I had this kind of working using offLineStorage, but then ran into the issue of not being able to set the database name to be the same in Python and QML. This is on a Raspberry Pi using the GPIO pins to retrieve data from sensors.

        1 Reply Last reply
        0
        • Everton FonsecaE Offline
          Everton FonsecaE Offline
          Everton Fonseca
          wrote on last edited by
          #4

          @JasonS I developed this way can this help you?

          import m7.Database 1.1

          Database {

          id: database
          driver: Database.SQLITE //Enum  define driver to  sql
          hostName: "localhost" // or ip
          nameBase:  "/home/name.db"
          
          Component.onCompleted: {
              
              var isOpen = database.open()
              
              if(isOpen){
                  
                  console.log("Database is open!")
                  
                  //start query
                  result.startQuery()
                  
              }
          }
          
          ResultSet{
              
              id: result
              database: database
              sqlQuery: "SELECT * FROM my_table"
              
              //Slot 
              onResultQuery:{
                  
                  //get query Columns
                  var column1 = value("column 1 name")
                  var column2 = value("column 2 name")
                  
                  //etc ...
                  
                  //call next row 
                  next()
                  
              }
              onEndQuery:{
                  
                  console.log("End process query")
                  
                  //close database
                  database.close()
              }
              
          }
          
          //function salve datas
          function salveDatas(){
              
              var isOpen =  database.open()
              
              if(!isOpen){
                  
                  console.log("not isOpen");
                  return false;
              }
              
              try{
                  
                  var st =  database.prepareStatement("INSERT INTO my_table (column_name) VALUES (?)")
                  
                  st.insert(0,'data')
                  
                  //salva o script database
                  var status = st.executeUpdate()
                  
              }catch(e){
                  
                  console.log("Error: "+e)
                  
              }finally{
                  
                  database.close()
                  
              }
              
              return status
          }
          

          }

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JasonS
            wrote on last edited by
            #5

            Looks promising. What is m7? I did a quick search and didn't get any hits. I found something similar to this on YouTube (https://www.youtube.com/watch?v=k_mKZ7xz-uA&list=FLwjNCTYuaSVzqAgz2AJ04sg&index=1) and this method uses oviont which I haven't heard of before either.

            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