[PyQt] why use the non-gui Qt classes in Python

Hans-Peter Jansen hpj at urpla.net
Fri Aug 24 02:16:26 BST 2018


On Samstag, 18. August 2018 10:29:03 Kyle Altendorf wrote:
> On August 18, 2018 6:23:38 AM EDT, J Barchan <jnbarchan at gmail.com> wrote:
> >On 18 August 2018 at 04:10, Kyle Altendorf <sda at fstab.net> wrote:> >
> >Why would I use QSQLDatabase, the network module if Python offers it
> >
> >> already?
> >
> >I think Florian has already mentioned this, but doing a lot of database
> >stuff I found the Python library ("mysql", I believe) awfully low-level
> >compared to what the Qt SQL classes offer.  Both for backend & frontend
> >(GUI) functionality, i.e. not *only* because I want to show it in a
> >QTableView.
> 
> Sure, maybe you want sqlalchemy or such over your DB driver.  Though with
> either there's the async issue.  I forget what async sqlalchemy options
> there may be.

QTableView does loading on demand behind the scenes. If you ever display a 
table with a few million rows, you will notice the difference. Guaranteed. ;-)

I've done all of them in the past (including using my own ORM on top of 
mysql). SqlAlchemy's ORM is really great for complex database operations in 
non UI processes, while PyQt is suffering a little from Qt's static datatype 
model and related mappers. I love Qt and PyQt, but it still suffers from a few 
weak spots. See e.g. https://bugreports.qt.io/browse/QTBUG-277 for details.

OTOH, PyQt excels in performance. As long as you don't do something silly 
database-wise, you really feel the power of a good C++ library, that make you 
forget, you're running a python script...

Before arriving here (around 08/2001!), I did database UIs in TkInter and 
WxPython. While the former sucked as hell in *every* aspect, the latter 
suffered from a lot of small details. At that time, toolkits hadn't a concept 
of database awareness what so ever.

Back on topic: A strong indication for not using Qt classes is code, that 
should be portable across non GUI environments. OTOH and apart from a few 
exceptions, I found using the Qt classes via PyQt well supported and doing as 
advertised. This is not self-evident, even in the Python eco system.

Cheers,
Pete


More information about the PyQt mailing list