Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Corroborate if a .sqlite file exists in a folder

    General and Desktop
    2
    2
    329
    Loading More Posts
    • 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.
    • Julian
      Julian last edited by

      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()

      mrjj 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion @Julian last edited by

        @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 Reply Quote 2
        • First post
          Last post