Qt Forum

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

    database

    General and Desktop
    3
    13
    3886
    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.
    • K
      kavin.motlani last edited by

      How do I install sql driver in qt and are there any ohter changes that I have to do? I am using wampserver and sql

      I tried to run the following code and It is giving me this error
      #include <QCoreApplication>
      #include <QDebug>
      #include <QtSql/QSqlDatabase>
      #include <QtSql/QSqlError>

      int main(int argc, char *argv[])
      {
      QCoreApplication a(argc, argv);

      QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL" );
      db.setHostName( "localhost" );
      db.setDatabaseName( "qtbook" );
      db.setUserName( "user" );
      db.setPassword( "password" );
      if( db.open() )
      {
          qDebug() << "connected";
      }
      else
      {
          qDebug() << db.lastError().text();
      }
      
      
      
      return a.exec();
      

      }

      error::

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSqlDatabase::~QSqlDatabase(void)" (_imp??1QSqlDatabase@@QEAA@XZ) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __cdecl QSqlDatabase::open(void)" (_imp?open@QSqlDatabase@@QEAA_NXZ) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: class QSqlError __cdecl QSqlDatabase::lastError(void)const " (_imp?lastError@QSqlDatabase@@QEBA?AVQSqlError@@XZ) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QSqlDatabase::setDatabaseName(class QString const &)" (_imp?setDatabaseName@QSqlDatabase@@QEAAXAEBVQString@@@Z) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QSqlDatabase::setUserName(class QString const &)" (_imp?setUserName@QSqlDatabase@@QEAAXAEBVQString@@@Z) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QSqlDatabase::setPassword(class QString const &)" (_imp?setPassword@QSqlDatabase@@QEAAXAEBVQString@@@Z) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl QSqlDatabase::setHostName(class QString const &)" (_imp?setHostName@QSqlDatabase@@QEAAXAEBVQString@@@Z) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: static class QSqlDatabase __cdecl QSqlDatabase::addDatabase(class QString const &,class QString const &)" (_imp?addDatabase@QSqlDatabase@@SA?AV1@AEBVQString@@0@Z) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QSqlError::~QSqlError(void)" (_imp??1QSqlError@@QEAA@XZ) referenced in function main

      main.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: class QString __cdecl QSqlError::text(void)const " (_imp?text@QSqlError@@QEBA?AVQString@@XZ) referenced in function main

      main.obj:-1: error: LNK2001: unresolved external symbol "__declspec(dllimport) public: static char * QSqlDatabase::defaultConnection" (_imp?defaultConnection@QSqlDatabase@@2PEADEA)

      debug\Db.exe:-1: error: LNK1120: 11 unresolved externals

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        First thing to do is to add

        QT += sql

        To your pro file

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

        K 1 Reply Last reply Reply Quote 0
        • K
          kavin.motlani last edited by kavin.motlani

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • K
            kavin.motlani @SGaist last edited by

            @SGaist Its already added. What should I do next?

            1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              What error did you got next ?

              What OS and Qt version are you running ?

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

              K 1 Reply Last reply Reply Quote 0
              • V
                Vince Golubic last edited by Vince Golubic

                Check the Database examples in Qt 4.x. Lots of good examples there that haven't changed much in Qt5.x.

                Basically if the Qt related library/drivers aren't installed (for database model you need) where they can be found in your Qt path (check all assumptions on where you have installed Qt) the qmake and linker will have issues and report errors.

                -Vince

                K 1 Reply Last reply Reply Quote 0
                • K
                  kavin.motlani @SGaist last edited by

                  @SGaist I am using windows 8 and QT 5.4
                  The errors I have mentioned in the post

                  1 Reply Last reply Reply Quote 0
                  • K
                    kavin.motlani @Vince Golubic last edited by

                    @Vince-Golubic How do I know whether the required libraries or drivers are installed?
                    And If they are not what should I do next?

                    1 Reply Last reply Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      Did you re-run qmake after adding QT += sql ?

                      As for the additional libraries, you should have the MySQL client libraries installed.

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

                      K 1 Reply Last reply Reply Quote 0
                      • K
                        kavin.motlani @SGaist last edited by

                        @SGaist the console screen appears with the following output

                        QSqlDatabase : QMySQL driver not loaded
                        QSqlDatabase : available drivers: QSLQITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
                        "Driver not loaded Driver not loaded"

                        1 Reply Last reply Reply Quote 0
                        • SGaist
                          SGaist Lifetime Qt Champion last edited by

                          Please, search the forum a bit, that problem has already been discussed many times.

                          You need to install the MySQL client libraries and add the path to them to your Run panel's PATH environment variable

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

                          K 1 Reply Last reply Reply Quote 0
                          • K
                            kavin.motlani @SGaist last edited by

                            @SGaist Can you just please tell me how to add path

                            1 Reply Last reply Reply Quote 0
                            • SGaist
                              SGaist Lifetime Qt Champion last edited by

                              Projects -> Run -> Run Environment -> edit the value of PATH

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