Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to connect to sqlite database

how to connect to sqlite database

Scheduled Pinned Locked Moved Unsolved General and Desktop
sqlite
6 Posts 5 Posters 13.2k 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.
  • A Offline
    A Offline
    ARASHz4
    wrote on 14 May 2016, 08:15 last edited by
    #1

    i want to connect to sqlite database
    this is my code:

    QSqlDatabase Database;
    
        Database.addDatabase("QSQLITE");
        Database.setDatabaseName("C:/Users/ARASH/Desktop/arash.db");
    
        if (!Database.open())
        {
            qDebug() << Database.lastError().text();
        }
    

    but return me "Driver not loaded Driver not loaded"

    I copy qsqlite.dll in sqldrivers folder inside my app folder but don't work

    P 1 Reply Last reply 14 May 2016, 10:41
    0
    • A ARASHz4
      14 May 2016, 08:15

      i want to connect to sqlite database
      this is my code:

      QSqlDatabase Database;
      
          Database.addDatabase("QSQLITE");
          Database.setDatabaseName("C:/Users/ARASH/Desktop/arash.db");
      
          if (!Database.open())
          {
              qDebug() << Database.lastError().text();
          }
      

      but return me "Driver not loaded Driver not loaded"

      I copy qsqlite.dll in sqldrivers folder inside my app folder but don't work

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 14 May 2016, 10:41 last edited by
      #2

      @ARASHz4 That dll should be inside sqldrivers directory.
      Have a look at this wiki page.

      157

      1 Reply Last reply
      1
      • P Offline
        P Offline
        panosk
        wrote on 14 May 2016, 16:52 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • P Offline
          P Offline
          panosk
          wrote on 14 May 2016, 16:53 last edited by
          #4

          You need to assign the connection like this:

          QSqlDatabase Database;
          
          Database = QSqlDatabase::addDatabase("QSQLITE");
          Database.setDatabaseName("C:/Users/ARASH/Desktop/arash.db");
          
          if (!Database.open())
          {
              qDebug() << Database.lastError().text();
          }
          
          1 Reply Last reply
          0
          • Y Offline
            Y Offline
            Yugui
            wrote on 31 May 2016, 16:16 last edited by
            #5

            about how to connect to sqlite database, what's the best form to do the connection?, once tiem at start and only get connexion or connect and close on each query.
            and is possible do update with bindvalue?

            thank you, sorry for my english!

            M 1 Reply Last reply 31 May 2016, 16:30
            0
            • Y Yugui
              31 May 2016, 16:16

              about how to connect to sqlite database, what's the best form to do the connection?, once tiem at start and only get connexion or connect and close on each query.
              and is possible do update with bindvalue?

              thank you, sorry for my english!

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 31 May 2016, 16:30 last edited by
              #6

              @Yugui
              Often best design is open once at start.
              and close at end.

              • and is possible do update with bindvalue?

              yes. it is.

              QSqlQuery query;
              query.prepare("INSERT INTO person (id, forename, surname) "
                            "VALUES (:id, :forename, :surname)");
              query.bindValue(":id", 1001);
              query.bindValue(":forename", "Bart");
              query.bindValue(":surname", "Simpson");
              query.exec();
              

              http://doc.qt.io/qt-5/qsqlquery.html

              1 Reply Last reply
              1

              • Login

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