PyQt5: specifying QSqlTableModel

Rich Shepard rshepard at appl-ecosys.com
Sat Jun 5 19:49:31 BST 2021


On Sat, 5 Jun 2021, Colin McPhail wrote:

> However, I do notice that the list of tables in your database has a column
> called 'Owner.' Do you think that in datasource.py you should use the
> version of open() that takes a username and password? If that's not
> relevant you could maybe ask for ideas on StackOverflow if you haven't
> already.

Colin,

To follow up on this idea.

1. Using only self.db.open() an empty window displays and the application
halts.

2. Adding (after setting the db name),
self.db.setHostName('aaa')
self.db.setUserName('bbb')
self.db.setPassword('ccc')
(with actual values throws this error):
Traceback (most recent call last):
   File "activitytypes.py", line 7, in <module>
     from PyQt5 import QtWidgets as qtw
   File "activitytypes.py", line 27, in __init__
     act_tbl = DBSetup()
   File "/home/rshepard/development/business_tracker/datasource.py", line 20, in __init__
     if not self.db.open():
NameError: name 'db' is not defined

Huh!

This 11 May, 2020 update to
<https://www.geeksforgeeks.org/pyqt5-qtsql-python/> uses mysql in its
example, but there is no open() for the database. After connecting it
defines a query.

I'm going to try this.

Rich


More information about the PyQt mailing list