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]QSqlDatabasd and undefined reference issue
Forum Updated to NodeBB v4.3 + New Features

[Solved]QSqlDatabasd and undefined reference issue

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 11.5k 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.
  • N Offline
    N Offline
    Naouali
    wrote on last edited by
    #1

    Hi guys ,
    I ùm trying to connet to mysql database but i get a list of undefined reference when i compile the project.
    Here's my code
    @#ifndef DATABASE_H
    #define DATABASE_H

    #include <QtSql/QSqlDatabase>
    #include <QtSql/QSqlError>
    #include <QDebug>

    class database
    {
    public:
    database(/QString username,QString password,QString host/);
    static bool createConnection();
    private:
    QString username;
    QString password;
    QString host;
    };

    #endif // DATABASE_H

    #include "database.h"

    database::database()
    {
    }
    static bool createConnection(){
    QSqlDatabase db =QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("mysql");
    db.setUserName("root");
    db.setPassword("morpheus2011");
    if (!db.open()){qDebug() << "Failed to connect to root mysql admin";return false;}
    else return true;
    }

    here's the undefined reference list:
    /home/aladin/Projects/Qt/pfe/database.cpp:7: error: undefined reference to QSqlDatabase::defaultConnection' /home/aladin/Projects/Qt/pfe/database.cpp:7: error: undefined reference to QSqlDatabase::addDatabase(QString const&, QString const&)'
    /home/aladin/Projects/Qt/pfe/database.cpp:8: error: undefined reference to `QSqlDatabase::setHostName(QString const&)'
    the list is long :)

    @
    can anyone help me ?

    Thanks in advance.

    1 Reply Last reply
    0
    • N Offline
      N Offline
      Naouali
      wrote on last edited by
      #2

      OK , i solved that added this line #include <QtSql> to database.h and QT +=sql to .pro file but when i run the program i get a new error :
      QSqlDatabase: QMYSQL driver not loaded
      QSqlDatabase: available drivers: QSQLITE
      Failed to connect to root mysql admin
      false

      how to solve that ?

      1 Reply Last reply
      1
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        click on the mysql tag on the right of your screen.
        You will find several explanations on how to get the mysql driver on different operating systems.

        or use this link:
        http://developer.qt.nokia.com/search/tag/mysql

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Naouali
          wrote on last edited by
          #4

          the problem was solved , i have two installation of Qt , i used the one installed from repository (ubuntu ) and it works fine .
          thanks for your help .

          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