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. QSqlDatabase open only existing database
Qt 6.11 is out! See what's new in the release blog

QSqlDatabase open only existing database

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.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.
  • T Offline
    T Offline
    Tikani
    wrote on last edited by
    #1

    How to prevent Qt from creating an empty database file (in case of SQLITE driver), when i'm using db.open()? I want to show error and terminate application if it's root folder doesn't contain SQLite3 database file, else - open dbfile or show error if it is corrupted.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      its the default action of SQLite engine AFASIK.
      You can just check yourself if file is in place

      #include <QFileInfo>
      
      bool fileExists(QString path) {
          QFileInfo check_file(path);
          // check if file exists and if yes: Is it really a file and no directory?
          return check_file.exists() && check_file.isFile();
      }
      
      T 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        its the default action of SQLite engine AFASIK.
        You can just check yourself if file is in place

        #include <QFileInfo>
        
        bool fileExists(QString path) {
            QFileInfo check_file(path);
            // check if file exists and if yes: Is it really a file and no directory?
            return check_file.exists() && check_file.isFile();
        }
        
        T Offline
        T Offline
        Tikani
        wrote on last edited by
        #3

        @mrjj
        Thanks for the clarifying, marking as solved.

        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