windows Qt 5.7 minwg 5.3 mariadb 10.2 QSqlDatabase: QMYSQL driver not loaded

812 Views Asked by At

it's been 10 hours that I search on the net. There is plenty of solution but none worked. I would like to know where to start. I just need a clue. Should i build my driver or there's a way that i don't need to do that. Which files i should use libmariadb or libmysqldb from mysql connector???

HELP PLEASE ;)

#-------------------------------------------------
#
# Project created by QtCreator 2018-03-22T18:50:22
#
#-------------------------------------------------

QT       += core gui
QT       += sql

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = dbconnect
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

...

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtSql>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

...

 #include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtSql/QtSql>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
       db.setHostName("localhost");
       db.setDatabaseName("test");
       db.setUserName("root");
       db.setPassword("test");
       if (!db.open()) {
           qDebug() << "Database error occurred";
       }

}

MainWindow::~MainWindow()
{
    delete ui;
}

...

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
Database error occurred
0

There are 0 best solutions below