0

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
  • 3
    Possible duplicate of [Qt: Windows 10: QMYSQL driver not loaded](https://stackoverflow.com/questions/46689703/qt-windows-10-qmysql-driver-not-loaded) – eyllanesc Mar 23 '18 at 01:39
  • I solve my problem with a newer version 5.10. The only problem is at school we use 5.7. – Francois Giguere Mar 24 '18 at 00:05

0 Answers0