Important: Please read the Qt Code of Conduct -

SQL connect to port, which is not opened...

  • Well, here I am...again... I have got this issue:
    I am connected to IP (localhost) with a specific port, let it be 33054 (on Linux). Although I am connecting to port 33054, which is closed, it connect to it!...
    Database driver: MySQL, the newest Qt...

    The code:
    class DB:
    tables = {}
    tables['admins'] = "admins"

        userdata = {}
        error_msg, error_code = (None, None)
        database = (None, None)
        def __init__(self):
            self.db = QSqlDatabase.addDatabase("QMYSQL")
        def setState(self, code, msg = None):
           Sets result code / error code of last action
            self.code = code
            if code == 0:
                self.error_code = None
                self.error_msg = None
                self.error_code = code
                self.error_msg = msg
            return code
        # ----------------------------------------------------------------------------------------------
        # ----------------------------------------------------------------------------------------------
        def connect(self, server):
            print self.db.port()
            ok =
            print self.db.lastError().databaseText()
            if ok:
                print "Connected to", server
                print "Error while connecting to the server", server
            return ok


  • That's because you are accessing to your self ( localhost), and it behaves differently.
    Try connecting via IP, or test your port with telnet.
    If it succeeds, your port is open.

  • No, that port is definitely closed. I have tried to connect also via other IP ( but it still connects. It looks like QtSql ignores setting port through setPort()...

  • Port blocking rules on your router do not apply on your local network and
    DB Manager automatically opens the configured port on your computer.

Log in to reply