Qt World Summit: Submit your Presentation

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

  • 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");
    bool result = DB.open();
    	QMessageBox::information(0, "Success", "Connected");
    	QMessageBox::information(0, "Error", DB.lastError().text());

    What can be the reason?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

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

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

  • Lifetime Qt Champion

    Did you close the connection first ?

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

Log in to reply