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. Corroborate if a .sqlite file exists in a folder
Forum Updated to NodeBB v4.3 + New Features

Corroborate if a .sqlite file exists in a folder

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 400 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.
  • J Offline
    J Offline
    Julian
    wrote on 8 Mar 2017, 19:08 last edited by
    #1

    Hello.

    How to know that a ".sqlite" file exits on the folder? For example if "intersection.sqlite" do not exist in the folder I have to do something and if it do not exist do another thing.

    What I had do is:

    
          QSqlDatabase *ultima;
          ultima=new QSqlDatabase();
          ultima->addDatabase("QSQLITE", "twelve_connection");
          ultima->setDatabaseName(ui->lineEdit_interseccion->text().remove(" ")+".sqlite"); //this is the name of sqlite's file
    
            if(ultima->isOpen())
            {
    
            crearTablaFallasNuevas();
            }
            else
            {
            agregarTablaFallasNuevas();
            }
            delete ultima ;
    

    But for what I see QSqlDatabase::isOpen just compare if ultima run, because it always goes to crearTablaFallasNuevas()

    M 1 Reply Last reply 8 Mar 2017, 19:51
    0
    • J Julian
      8 Mar 2017, 19:08

      Hello.

      How to know that a ".sqlite" file exits on the folder? For example if "intersection.sqlite" do not exist in the folder I have to do something and if it do not exist do another thing.

      What I had do is:

      
            QSqlDatabase *ultima;
            ultima=new QSqlDatabase();
            ultima->addDatabase("QSQLITE", "twelve_connection");
            ultima->setDatabaseName(ui->lineEdit_interseccion->text().remove(" ")+".sqlite"); //this is the name of sqlite's file
      
              if(ultima->isOpen())
              {
      
              crearTablaFallasNuevas();
              }
              else
              {
              agregarTablaFallasNuevas();
              }
              delete ultima ;
      

      But for what I see QSqlDatabase::isOpen just compare if ultima run, because it always goes to crearTablaFallasNuevas()

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 8 Mar 2017, 19:51 last edited by
      #2

      @Julian
      Hi
      Its best to use QFileInfo as as far as I remember, the SQL open will create new db if not there.

      bool fileExists(QString path) {
          QFileInfo check_file(path);
          // check if file exists and if yes: Is it really a file and no directory?
          if (check_file.exists() && check_file.isFile()) {
              return true;
          } else {
              return false;
          }
      }
      
      1 Reply Last reply
      2

      1/2

      8 Mar 2017, 19:08

      • Login

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