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]Database connexion in a GUI apps with Qt5 (Mingw) seems impossible ?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Database connexion in a GUI apps with Qt5 (Mingw) seems impossible ?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.1k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Marco_105
    wrote on last edited by
    #1

    Hello,

    My driver's compilation looks fine (MySQL) and the dispatching is:

    Qt/Qt5.0.1/5.0.1/mingw47_32/bin >libmysql.dll
    Qt/Qt5.0.1/5.0.1/mingw47_32/lib >libqsqlmysql.a et libqsqlmysqld.a
    Qt/Qt5.0.1/5.0.1/mingw47_32/lib/plugins/sqldrivers >qsqlmysql.dll et qsqlmysqld.dll

    That's works fine in a Console app only !...

    but when i try with a GUI apps and following code:

    @#include "dialog.h"
    #include <QApplication>

    bool createConnection()
    {
    QString myDriver = "QMYSQL"; //"QODBC"

    QSqlDatabase db = QSqlDatabase::addDatabase(myDriver);
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("");
    db.setDatabaseName("test"); //"ODBC_DBTest"
    
    if(!db.open())
    {
        qDebug() << "Connexion FAILED.";
        qDebug() << "Driver disponible: " << db.drivers();
        qDebug() << "Driver fonctionnel" << myDriver << ":" << db.isDriverAvailable(myDriver);
        qDebug() << "numero de l'erreur: " << db.lastError().number();
        qDebug() << "database erreur: " << db.lastError().databaseText();
        qDebug() << "driver erreur: " << db.lastError().driverText();
        return false;
    
    }else{
        qDebug() << "Your are now connect to " << db.hostName();
        return true;
    }
    

    }

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    if(!createConnection())
    return 1;

    Dialog w;
    w.show();
    
    return a.exec&#40;&#41;;
    

    }
    @

    Connexion FAILED.
    Driver disponible: ("QSQLITE", "QMYSQL", "QMYSQL3", "QODBC", "QODBC3")
    Driver fonctionnel "QMYSQL" : true
    numero de l'erreur: 2005
    database erreur: "Unknown MySQL server host 'localhost' (0)"
    driver erreur: "QMYSQL: Unable to connect"

    What did i miss or how can i find a hack for it ?

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      the error message just says that i couldn't find a mysql server on "localhost"
      Are you sure that you have a mysql server running on your computer?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        alternatively you can try to use "127.0.0.1" .
        And make sure that C:\Windows\System32\drivers\etc\hosts has the following entry in it:
        @127.0.0.1 localhost@

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Marco_105
          wrote on last edited by
          #4

          I have wamp server with mysql, maybe there is a special config with it ?

          Don't know exactly, why that works in a console apps ?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Marco_105
            wrote on last edited by
            #5

            Yes, i know that host file is Ok and i can also have connexion by cmd.exe command...

            1 Reply Last reply
            0
            • M Offline
              M Offline
              Marco_105
              wrote on last edited by
              #6

              Hello World...

              Seems nobody can help on that way ?

              Why connexion on database works on a console apps and will not on a gui apps

              Because security is active and break this behaviour...

              Responsible: Firewall

              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