0

Recently I have installed Zorin os and qt creator from [enter link description here][1]

[1]: https://flathub.org. I need to connect the lamp server which I have installed. I am using qt creator and here is my sample code to connect the MySQL database.

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("csms");
    db.setUserName("root");
    db.setPassword("");
    bool ok = db.open();

    if(ok) {
        qDebug() << "Database connected." << Qt::endl;
    } else {
        qDebug() << "Database connection error." << db.lastError ()<< Qt::endl;
    }

But failed. I am googling the last two days but no luck. Now I am here. I need help.

2
  • how does it fail? Commented Sep 10, 2022 at 14:02
  • it gives "QSqlDatabase: QMYSQL driver not loaded error" Commented Sep 10, 2022 at 14:13

1 Answer 1

0

Use qDebug() << QSqlDatabase::drivers() look which drivers you have.

If the QMYSQL is not on the list - compile it: https://doc.qt.io/qt-6/sql-driver.html

2
  • QMYSQL driver is missing how to compile/load this driver ? Commented Sep 10, 2022 at 17:10
  • I am new so please guide me. thanks Commented Sep 10, 2022 at 17:16

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.