0

I can't connect to my SQL database using QSqlDatabase. My system is: Windows 11 Qt 6.9.0 llvm-mingw1706_64 MySql 8.0.41 running on a CentOs virtual machine.

I extract libmysql.dll, libmysql.lib and all .h files from mysqld installation file. Following the instruction from qt I compiled the mysql drivers and then I found qsqlmysql.dll in "C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/"

Then I copied libmysql.dll in my progrma directory and set QT_DEBUG_PLUGINS=1.

QSqlDatabase.drivers() show that I have all drivers and qslmysql is loaded, but I still ha an error on QSqlDatabase open.

This is the application output:

qt.core.plugin.factoryloader: checking directory path "C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers" ...
qt.core.plugin.factoryloader: looking at "qsqlibase.dll"
qt.core.plugin.loader: Found metadata in lib C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlibase.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QIBASE"
        ]
    },
    "archlevel": 1,
    "className": "QIBaseDriverPlugin",
    "debug": false,
    "version": 395520
}


qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QIBASE")
qt.core.plugin.factoryloader: looking at "qsqlite.dll"
qt.core.plugin.loader: Found metadata in lib C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlite.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QSQLITE"
        ]
    },
    "archlevel": 1,
    "className": "QSQLiteDriverPlugin",
    "debug": false,
    "version": 395520
}


qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QSQLITE")
qt.core.plugin.factoryloader: looking at "qsqlmimer.dll"
qt.core.plugin.loader: Found metadata in lib C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlmimer.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QMIMER"
        ]
    },
    "archlevel": 1,
    "className": "QMimerSQLDriverPlugin",
    "debug": false,
    "version": 395520
}


qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QMIMER")
qt.core.plugin.factoryloader: looking at "qsqlmysql.dll"
qt.core.plugin.loader: Found metadata in lib C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlmysql.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QMYSQL",
            "QMARIADB"
        ]
    },
    "archlevel": 1,
    "className": "QMYSQLDriverPlugin",
    "debug": false,
    "version": 395520
}


qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QMYSQL", "QMARIADB")
qt.core.plugin.factoryloader: looking at "qsqloci.dll"
qt.core.plugin.loader: Found metadata in lib C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqloci.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QOCI"
        ]
    },
    "archlevel": 1,
    "className": "QOCIDriverPlugin",
    "debug": false,
    "version": 395520
}


qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QOCI")
qt.core.plugin.factoryloader: looking at "qsqlodbc.dll"
qt.core.plugin.loader: Found metadata in lib C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlodbc.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QODBC"
        ]
    },
    "archlevel": 1,
    "className": "QODBCDriverPlugin",
    "debug": false,
    "version": 395520
}


qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QODBC")
qt.core.plugin.factoryloader: looking at "qsqlpsql.dll"
qt.core.plugin.loader: Found metadata in lib C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlpsql.dll, metadata=
{
    "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface",
    "MetaData": {
        "Keys": [
            "QPSQL"
        ]
    },
    "archlevel": 1,
    "className": "QPSQLDriverPlugin",
    "debug": false,
    "version": 395520
}


qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QPSQL")
qt.core.plugin.factoryloader: checking directory path "C:/Users/00005197/OneDrive - ansaldoenergiagroup/Documenti/Lavori/C++/Catalog/build/Desktop_Qt_6_9_0_llvm_mingw_64_bit-Debug/debug/sqldrivers" ...
qt.core.library: "C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlmysql.dll" loaded library
"C:/Qt/6.9.0/llvm-mingw_64/plugins/iconengines/qsvgicon.dll" unloaded library 
"C:/Qt/6.9.0/llvm-mingw_64/plugins/platforms/qwindows.dll" unloaded library 
"C:/Qt/6.9.0/llvm-mingw_64/plugins/sqldrivers/qsqlmysql.dll" unloaded library 
"C:/Qt/6.9.0/llvm-mingw_64/plugins/styles/qmodernwindowsstyle.dll" unloaded library 
15:10:19: C:\Users\00005197\OneDrive - ansaldoenergiagroup\Documenti\Lavori\C++\Catalog\build\Desktop_Qt_6_9_0_llvm_mingw_64_bit-Debug\debug\Catalog.exe exited with code 0

Can someone explain me what I've done wrong? Thank you.enter code here

0

1 Answer 1

0

Problem solved.

My original code was:

m_Db.addDatabase("QMYSQL");

It have to be:

m_Db = QSqlDatabase::addDatabase("QMYSQL");

In the first case

bool ok = m_Db.open();

even if driver il correctly loaded.

Now I have a different proble, if I run directly the program, it is able to connect to the remote database. If I run it inside debugger, I receive this error:

"Open database failed: Can't create TCP/IP socket (10106) QMYSQL: Unable to connect"

Someone know how to configure debugger so to avoid this error?

Thank you.

Sign up to request clarification or add additional context in comments.

1 Comment

Please open a new question for a new issue! People are much less likely to see an issue if it's inside an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.