1

I was trying to make connection to my PSQL database but when I checked:

dbliste = QtSql.QSqlDatabase.drivers()  print(dbliste),

i got this:

['QSQLITE', 'QODBC', 'QODBC3']

Why I don't have drivers for QPSQL installed? Where can I download them?

from PyQt5 import QtWidgets, QtSql

def createConnection():
    db = QtSql.QSqlDatabase.addDatabase("QPSQL")
    db.setHostName('localhost') 
    db.setPort(5432) 
    db.setDatabaseName('DB_real') 
    db.setUserName('postgres') 
    db.setPassword('****') 


if not db.open():
    QtWidgets.QMessageBox.critical(None, "Cannot open database",
                         "Unable to establish a database connection.\n"

                         "Click Cancel to exit.", QtWidgets.QMessageBox.Cancel)
    return False

dbliste = QtSql.QSqlDatabase.drivers() 
print(dbliste)
Al Imran
  • 882
  • 7
  • 29

2 Answers2

0

I found out that first problem was in different version of PostgreSQL and QT. Now I am deinstalling and installing the right versions and then I will try to connect it. I hope it works...

0

Simple solution after two days is just to install 'Pyqt5' using pip even if is already installed with conda or installer:

pip install PyQt5