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. SQlite connection success then failure?
Forum Updated to NodeBB v4.3 + New Features

SQlite connection success then failure?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 519 Views 2 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.
  • M Offline
    M Offline
    Mocha Shakea Khan
    wrote on last edited by
    #1

    I'm trying to connect sqlite databse, but i'm having a confusing issue. I've run qmake and added sql to .pro file and included:

    #include <QtSql/QSqlDatabase>
    #include <QDebug>
    #include <QFileInfo>
    #include <QString>
    #include <QMessageBox>

    in the header file.

    in my login.cpp i have the following code:

    QSqlDatabase db= QSqlDatabase::addDatabase("QSQLITE", "LMS");
    db.setDatabaseName("D:/Documents/Sqlite Database/LMS.db");

    if (db.open())
        //ui->db_label->setText("Connected...");
        QMessageBox::information(this,"success","success");
    else {
        ui->db_label->setText("Failed to connect");
    }
    

    When i run the code i get the message saying success, but once i click ok the application output states database failed to connect.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Where do you click ok? Please provide a complete, mimimal! example - from your code we don't see anything which could go wrong here.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Are you calling open from several different classes ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        M 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Where do you click ok? Please provide a complete, mimimal! example - from your code we don't see anything which could go wrong here.

          M Offline
          M Offline
          Mocha Shakea Khan
          wrote on last edited by
          #4

          @Christian-Ehrlicher
          Qmessagebox will display a message if db is open. When i run the code a message box does appear displaying success. I click ok on the message box then the application output states that the database failed to connect right before the window appears.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Mocha-Shakea-Khan said in SQlite connection success then failure?:

            database failed to connect

            Qt does not output such a string. Do you mean your db_label is displaying "Failed to connect"? Please be more precise... and if so it looks like you're calling your function twice.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              Are you calling open from several different classes ?

              M Offline
              M Offline
              Mocha Shakea Khan
              wrote on last edited by
              #6

              @SGaist

              I feel so stupid; i forgot i tried to connect to qodbc in the main.cpp this morning. I deleted the code and every thing is good now.

              mrjjM 1 Reply Last reply
              0
              • M Mocha Shakea Khan

                @SGaist

                I feel so stupid; i forgot i tried to connect to qodbc in the main.cpp this morning. I deleted the code and every thing is good now.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Mocha-Shakea-Khan
                Oh so it was in main where it printed the message and really not related to Sqllite?
                Anyway, shit happens, just mark as solved and back to programming :)

                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