Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Connect to the MYSQL server successful but can't see any data
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    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/

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        stereomatching
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          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?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            stereomatching
            wrote on last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              cogitsolutions
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  stereomatching
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved