Important: Please read the Qt Code of Conduct -

database.tables() returned empty after connected to mariadb

  • After I used driver "QMYSQL" to connect to mariadb, the database.tables() returned

    empty. I have tried qt4.8 and qt5.3.2, got the same result.But when I connected to

    sqlite, there is no problem.

    My OS is opensuse 13.2 64 Bit.

    My code is :
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QDebug>
    #include <QStringList>

    int main()
    QSqlDatabase database = QSqlDatabase::addDatabase("QMYSQL");
    if (!
    return 1;
    return 0;

    Program output :

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you rebuild the driver before using it with MariaDB ?

  • @lxyevl Hi, I can reproduce your behaviour. The culprit seems to be the database itself. For some reason QSqlDatabase::tables() doesn't like to show the tables from the MySQL internal database information_schema. When I use another database, tables() works just fine.
    Even when I used QSqlDatabase::tables(QSql::AllTables) -- show everything, including system tables -- the ones contained in information_schema didn't show up. Eventually a bug but might also be a security feature of MySQL not to present internal data?
    But I found a workaround. Maybe this would help you:

    QSqlQuery q;
    q.exec( "select TABLE_NAME,TABLE_SCHEMA from TABLES where TABLE_SCHEMA='information_schema' LIMIT 10" );
    while( {
     qDebug() << q.value(0) << ", " << q.value(1);

    This query selects the name and schema from the information_schema.tables system table that contains the meta data of all tables of all databases -- even those in information_schema and itself.

  • @SGaist No, I didn't. I installed the driver by zypper.

  • @simow thanks for the answer.

Log in to reply