Debugging PyQt5 QSql

已回答

Hi

I have challenge finding a bug when calling db.open(), I can't trace the code, anyone who have an idea how to debug QtPy4/5?

Running Win10 64 on Bootcamp Mac Pro , Python 3.6.1

The code for short is

from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtSql import QSqlDatabase
from configparser import RawConfigParser

def createconnection():
parser = RawConfigParser()
parser.read('Qtabwindow.cfg')
result =QSqlDatabase.isDriverAvailable('QMYSQL')
print(result)
db = QSqlDatabase.addDatabase('QMYSQL')
db.setHostName(parser.get("DEFAULT", 'Hostname'))
db.setDatabaseName(parser.get('DEFAULT', 'DatabaseName'))
db.setUserName(parser.get('DEFAULT', 'UserName'))
db.setPassword(parser.get('DEFAULT', 'PassWord'))

if not db.open():
'''
QMessageBox.critical(None, 'Cannot open database \
Unable to establish a database connection.\
This example needs SQL support.Please read the Qt SQL',
QMessageBox.Cancel)
'''
return False
return True

 

0
Avatar
Permanently deleted user
-1

Hi Gert! Does "-1" mean that the problem is not relevant for you now?

0
Avatar
Permanently deleted user

Hi Anna! Yes, the problem is still very relevant and I can't figure out how to solve it. I have checked almost all sites like Stack overflow and also contacted Phil Thompson at Riverbank Computing, but no reply.

0

请先登录再写评论。