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. QT mysql connectivity issue on other than default port
Forum Updated to NodeBB v4.3 + New Features

QT mysql connectivity issue on other than default port

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 182 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
    Manish Bhavsar
    wrote on last edited by
    #1

    Hi,

    I have QT mysql connectivity issue.

    I have created one docker instance where I have installed mysql. This mysql instance is running
    on port 6603 and not a regular port of 3306.
    This port is open and is accessible from outside as well. Now I am connecting to this mysql instance
    from all other applications which is not built using QT, like I am able to connect using node js or
    any other 3rd party mysql editor. This means there is no connectivity issue.
    But when I try to connect to this server using QSqlDatabase, it is either not connecting or says access denied.
    However, if I change the above server port from 6603 to default 3306, QT application is able to connect.
    Not getting where the things are going wrong. I have used below code of QT.

    QJsonObject jo = getConnectionDetails(); // getConnectionDetails has all values of actual connections.
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL",jo.value("conn_name").toString());
    db.setHostName(jo.value("hostname").toString());
    db.setDatabaseName(jo.value("dbname").toString());
    db.setUserName(jo.value("username").toString());
    db.setPassword(jo.value("password").toString());
    db.setPort(jo.value("port").toInt());
    if (!db.open()){
            error = db.lastError().databaseText();
            qDebug() << "Connection error: " + error;
            return false;
        }
        return true;
    

    Above code is part of connector function.
    Please suggest why this happening?

    Cheers

    Manish

    Christian EhrlicherC 1 Reply Last reply
    0
    • M Manish Bhavsar

      Hi,

      I have QT mysql connectivity issue.

      I have created one docker instance where I have installed mysql. This mysql instance is running
      on port 6603 and not a regular port of 3306.
      This port is open and is accessible from outside as well. Now I am connecting to this mysql instance
      from all other applications which is not built using QT, like I am able to connect using node js or
      any other 3rd party mysql editor. This means there is no connectivity issue.
      But when I try to connect to this server using QSqlDatabase, it is either not connecting or says access denied.
      However, if I change the above server port from 6603 to default 3306, QT application is able to connect.
      Not getting where the things are going wrong. I have used below code of QT.

      QJsonObject jo = getConnectionDetails(); // getConnectionDetails has all values of actual connections.
      QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL",jo.value("conn_name").toString());
      db.setHostName(jo.value("hostname").toString());
      db.setDatabaseName(jo.value("dbname").toString());
      db.setUserName(jo.value("username").toString());
      db.setPassword(jo.value("password").toString());
      db.setPort(jo.value("port").toInt());
      if (!db.open()){
              error = db.lastError().databaseText();
              qDebug() << "Connection error: " + error;
              return false;
          }
          return true;
      

      Above code is part of connector function.
      Please suggest why this happening?

      Cheers

      Manish

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Manish-Bhavsar said in QT mysql connectivity issue on other than default port:

      jo.value("port").toInt()

      Did you actually check if it returns what you're expecting?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Beside the port number.

        What exact error are you getting ?

        Do you have the MySQL plugins for your Qt installation ?
        How did you install Qt ?
        Which version is it ?
        On which OS ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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