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. Load MySQL Database, can't connect to host. [SOLVED]
QtWS25 Last Chance

Load MySQL Database, can't connect to host. [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.5k 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.
  • L Offline
    L Offline
    laetis
    wrote on last edited by
    #1

    Hi,

    I am trying to connect to a database using the following code:
    @#include <QtCore/QCoreApplication>
    #include <QtSql>
    #include <iostream>
    #define q2c(string) string.toStdString()
    int main(int countArg, char **listArg)
    {
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("pivoine");
    db.setUserName("root");
    db.setPassword("passwd");
    db.setDatabaseName("DBChemAlive");
    if(db.open())
    {
    std::cout << "Connected " << q2c(db.hostName()) << std::endl;
    db.close();
    }
    else
    {
    std::cout << "Error :(" << std::endl << q2c(db.lastError().text()) << std::endl;
    }}@

    Here the output at execution:
    Error :(
    Can't connect to MySQL server on 'pivoine' (111) QMYSQL: Unable to connect

    I don't know what to try, thanks for your help.

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

      what about the port? Is the server running on a different port (default port for MYSQL server is 3306)? If so you need to specifiy it. But it wouldn't be bad to add it anyway to rid out this cause.

      --- 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
      • G Offline
        G Offline
        gosztola.laszlo
        wrote on last edited by
        #3

        Can the application load the database plugin?
        Try to list the available database drivers with QSqlDatabase::drivers

        1 Reply Last reply
        0
        • L Offline
          L Offline
          laetis
          wrote on last edited by
          #4

          In fact it was a stupid mistake of mane related to the hostame for mysql.
          So now it is fine.

          Thanks

          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