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. [SOLVED] Qt Creator in Kubuntu QDatabase - QSQLITE - driver not found
QtWS25 Last Chance

[SOLVED] Qt Creator in Kubuntu QDatabase - QSQLITE - driver not found

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.3k 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
    arsinte_andrei
    wrote on last edited by
    #1

    [../../../electricity/src/AtpCore/AtpDb.cpp:49, static bool AtpDb::setNewConnection()]
    Critical: couldn't connect to database Error[ "Driver not loaded Driver not loaded" ] "/media/andrei/Munca/atp-trading/qt-electricity/electricity/dbfile/electricityy.atpdb"
    [kernel/qsqlquery.cpp:968, bool QSqlQuery::prepare(const QString&):]
    Warning: QSqlQuery::prepare: database not open

    does anyone know why is not loading the driver?

    @QSqlDatabase *myNewdb = new QSqlDatabase();
    if (!QSqlDatabase::isDriverAvailable(dbNewType)){
    return false;
    }
    myNewdb->addDatabase(dbNewType);
    qDebug() << dbNewType;
    myNewdb->setDatabaseName(dbNewPath);
    if (!myNewdb->open()){
    qCritical() << "couldn't connect to database Error[" << myNewdb->lastError().text() << "]" << dbPath;
    return false;
    } else {
    qDebug() << "succsessfully connected to database " << dbPath;
    }@
    the value of dbNewType is "QSQLITE"
    this is the list ov available drivers printed with:
    @qDebug() << QSqlDatabase::drivers();
    Debug: ("QSQLITE", "QMYSQL", "QMYSQL3", "QPSQL", "QPSQL7") @
    kindly help me to get out of this.. lost few hoour only today.. hm... frustratd because of it...
    is simple but I can not see where is it..

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mr. Puskevit
      wrote on last edited by
      #2

      I think you are using addDatabase wrong. It's a static function so you should use like this.

      QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");

      You should check QSqlDatabase documentation.
      "QSqlDatabase":http://qt-project.org/doc/qt-5/QSqlDatabase.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        arsinte_andrei
        wrote on last edited by
        #3

        ok... but as yu can see I've used to initialize the database
        @QSqlDatabase *myNewdb = new QSqlDatabase();@
        so now I can not use
        @QSqlDatabase db = QSqlDatabase::addDatabase(“QSQLITE”);@

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mr. Puskevit
          wrote on last edited by
          #4

          @QSqlDatabase *myNewdb = new QSqlDatabase(QSqlDatabase::addDatabase(“QSQLITE”));@

          This should work.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            arsinte_andrei
            wrote on last edited by
            #5

            unfortunatele I have to accept that this will work like that but I do not understand why
            @myNewdb->setDatabaseName(dbNewPath);@
            is provided and is not working??
            any way now I've changed the constructor and is fine
            @
            QSqlDatabase myNewdb;
            if (!QSqlDatabase::isDriverAvailable(dbNewType)){
            return false;
            }
            myNewdb = QSqlDatabase::addDatabase(dbNewType);
            qDebug() << dbNewType;
            myNewdb.setDatabaseName(dbNewPath);
            if (!myNewdb.open()){
            qCritical() << "couldn't connect to database Error[" << myNewdb.lastError().text() << "]" << dbPath;
            return false;
            } else {
            qDebug() << "succsessfully connected to database " << dbPath;
            }
            @

            but that is not nice at all for what i have to create... any way..... I've worked around and is working almost fine

            1 Reply Last reply
            0
            • A Offline
              A Offline
              arsinte_andrei
              wrote on last edited by
              #6

              [quote author="Mr. Puskevit" date="1406050768"]@QSqlDatabase *myNewdb = new QSqlDatabase(QSqlDatabase::addDatabase(“QSQLITE”));@

              This should work.
              [/quote]

              I will try this later on.. now I will take a break.. see you at around 11 or 12 in this evening...
              Until then.. have a great joy programing.. and debugging - this is most time consumming for me :)

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

                Don't use a pointer to a QSqlDatabase, there's no need for that. It's all well explained in the documentation.

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

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  arsinte_andrei
                  wrote on last edited by
                  #8

                  well any way the pointer is not working.. but for what I'm doing I will need a pointer.... and now just for ypu to get an Ideea why I will need a pointer here you have...

                  • AtpDb.cpp
                    http://pastebin.com/JK5enqeB

                  *AtpDb.h
                  http://pastebin.com/eQ2Xpec4

                  my wish is to access the class just from any side of the program without any need to do all the the checks and not to init anything just by
                  @AtpDb::Select(select statement...)@
                  and each have it's oun return that is convenient for me...
                  plus I can unini with @AtpDb::uninit;@ and I'm avoiding SIGSEGV witch I wish to avoid.. so basicly because of SIGSEGV I will need this to be a pointer.. any help for creating a singleton?

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

                    Writing a wrapper class is fine, but I don't see the point of inheriting QSqlDataBase, you are not extending it, you are just using it.

                    Again I encourage you to re-read the documentation of QSqlDataBase, you don't need to keep a pointer to the current database connection. You can retrieve it when needed and from your code it doesn't look like you have to. QSqlQuery uses the default connection automatically so you don't have to pass anything special. And in the case you would, you can retrieve the correct connection with QSqlDatabase::database("my_other_connection")

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

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      arsinte_andrei
                      wrote on last edited by
                      #10

                      yep, this is true, but what I've been thinking to archive is to be able to manage the connection. user is able too change the database file in the settings and if the user change the database file, the file can be wrong so I have to reset the connection and to know if is a valid connection and to destroy the old connection and to be only one connection at any time so like a singleton. Because I wish to pass as the argument to QSqlQuery the connection and to check is the connection is available... I'm afraid that will never happen for the user to change the database file or to create a new one and the class not to be destroyed and recreated...
                      but yes I've read many times the QSqlDatabase so I've just changed my code and at the moment it doesn't extend anything. is just a pure class. I will see the behaviour.. but now When I have already a connection and create a new one.. I do not know why I receive the SIGSEGV on the cloase of the program (mainWindow). witch is not received if I do n ot create a new connection and stick with the one created at the beginning.. I will debug it.. any way.. many thanks for your help.. highly apreciated.

                      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