Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt5 MYSQL “open()” method return true even with wrong credentials
Qt 6.12 LTS is out! See what's new in the release blog

Qt5 MYSQL “open()” method return true even with wrong credentials

Scheduled Pinned Locked Moved General and Desktop
qt5.5qmysql
5 Posts 2 Posters 2.8k Views 2 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    While writing a Qt5 application that uses QSqlDatabase with MySQL, I encountered a strange behavior when I try to connect to datebase. QSqlDatabase::open() returns true even with wrong username, password and port. That's my code:

    QSqlDatabase DB = QSqlDatabase::addDatabase("QMYSQL", "Connection");
    DB.setHostName(Interface.InputIP->text());
    DB.setDatabaseName("connectdb");
    DB.setPort(Interface.InputPort->value());
    DB.setUserName(Interface.InputLog->text());
    DB.setPassword(Interface.InputPass->text());
    bool result = DB.open();
    if(result)
    	QMessageBox::information(0, "Success", "Connected");
    else
    	QMessageBox::information(0, "Error", DB.lastError().text());
    DB.close();
    

    What can be the reason?

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

      Hi and welcome to devnet,

      Just a silly idea but, are you sure the database you are accessing is protected ?

      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
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        I'll write differently.
        If i write all credentials correctly i can connect to database, and method "open" return true which is proper behavior.
        But, if i write all credentials incorrectly (without IP) or i try to connect to disabled database method "open" again return true.
        If I use external application to connect to my database and it's works perfectly.

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

          Did you close the connection first ?

          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
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by A Former User
            #5

            No, I close connection after try to connect and after conditional statement, as it is in the code in first post.

            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
            • Unsolved