[Solved]Connect to the MYSQL server successful but can't see any data



  • Using Qt5.2 to connect to the mysql(localhost) with the example(sqlbrowser) come with Qt5.2.I can connect to the db(db.open() == true) but can't see any table of that db.

    If every thing work fine, it should show the name of the tables as the image show(sqlbrowser00), but the db I connected to never show any existence of the table(empty result).

    "sqlbrowser00":http://postimg.org/image/a7d2jpbr7/

    My OS : win7

    connect to : Fedora core release 5, kernel 2.6.15-1.2054_FC5 smp on an i686

    I am a newbie of mysql, if the data I provided are not enough, please give me some suggestions(what data should I provide?)

    "sqlbrowser01":http://postimg.org/image/twc63m1v5/



  • You don't tell us how you are trying to get the table names to display or what you have done to debug the problem. It could be in your (invisible) code, that the user you connect with does not have relevant permissions, or that the database is actually empty.



  • Sorry for my ignorance.

    [quote author="ChrisW67" date="1389230744"]You don't tell us how you are trying to get the table names to display or what you have done to debug the problem. It could be in your (invisible) code, that the user you connect with does not have relevant permissions, or that the database is actually empty. [/quote]

    1 : it is same as the codes in the example(sqlbrowser)

    @
    void ConnectionWidget::refresh()
    {
    tree->clear();
    QStringList connectionNames = QSqlDatabase::connectionNames();
    qDebug()<<"connection names\n"<<connectionNames;
    bool gotActiveDb = false;
    for (int i = 0; i < connectionNames.count(); ++i) {
    QTreeWidgetItem *root = new QTreeWidgetItem(tree);
    QSqlDatabase db = QSqlDatabase::database(connectionNames.at(i), false);
    root->setText(0, qDBCaption(db));
    if (connectionNames.at(i) == activeDb) {
    gotActiveDb = true;
    setActive(root);
    }

        if (db.isOpen()) {
            QStringList tables = db.tables(QSql::AllTables);
            qDebug()<<"tables\n"<<tables;
            for (int t = 0; t < tables.count(); ++t) {
                QTreeWidgetItem *table = new QTreeWidgetItem(root);
                table->setText(0, tables.at(t));
            }
        }
        
    }
    if (!gotActiveDb) {
        qDebug()<<"do not exist activeDb";
        activeDb = connectionNames.value(0);
        setActive(tree->topLevelItem(0));
    }
    
    tree->doItemsLayout(); // HACK
    

    }
    @

    if the database do exist, it should looks like
    "sqlbrowser00":http://postimg.org/image/a7d2jpbr7/

    2 : the database is not empty

    edit : I use the codes
    @ QSqlDatabase db = QSqlDatabase::addDatabase("MYSQL");@
    to connect but not @ QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");@
    maybe this is the problem



  • Sorry, missed the bit about it being the example, although it seems you have modified that anyway. Given that the SQL driver name is "QMYSQL", using "MYSQL" would fail and also means that:

    bq. I can connect to the db(db.open() == true)

    would not be true.

    What do the qDebug() statements print?



  • [quote author="ChrisW67" date="1389240374"]Sorry, missed the bit about it being the example, although it seems you have modified that anyway. Given that the SQL driver name is "QMYSQL", using "MYSQL" would fail and also means that:

    bq. I can connect to the db(db.open() == true)

    would not be true.

    What do the qDebug() statements print?[/quote]

    The qDebug() do not show anything.



  • qDebug statement should print debugging messages so that you can follow the execution process.
    If you are looking for "Web design":http://www.cogitsolutions.com and "web development":http://www.cogitsolutions.com services then contact us. Our expert developers will work with you closely to develop fast and secure web site.



  • You are running this is an environment where you can see the debug output, aren't you?

    Line 5 unconditionally outputs a list of connection names. If the qDebug() statements are not outputting anything then refresh() is not being called.
    Line 9 will not open a database connection that exists but is not already open and line 18 will output a list of table names if your database isOpen(). It appears this is not the case.

    Have you installed the relevant Mysql client libraries and they are available to the running process?



  • Thanks guys, the problem already solved, the plugin of Qt depend on another dll--libmysql.dll.Maybe the document of Qt should mention about this.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.