Application stalls with query/table models in PyQt5
-
Hi, I'm working on a small application to access a database. I wrote it with PyQt4 but I'm now adapting it to PyQt5, really a piece of cake until now because the code is very simple.
So simple, in fact, that I cannot find the reason it doesn't work with PyQt5 as it did with the previous version. I have various QDialogs for editing the contents of different tables using a QDataWidgetMapper. I create the data model like this:
model = QSqlTableModel(self)
model.setTable("myTable")and the execution stalls on that last line, no crash, no segmentation fault, nothing. It just stalls indefinitely. It happens the same with QSqlQueryModel when calling setQuery(), but only on some dialogs, others don't, and they are identical (only changes the table's name and the fields.
Any clues? where should I look to fix this?
-
Hi and welcome to devnet,
You should add which version of Qt 5 you are using as well as QSL driver
-
Did you check if you have any error from your database prior to setTable ?
Is the MySQL server your own machine or another one ?
-
It is on another machine, but I don't think it's a mysql problem because, if I switch the headers back to PyQt4, the same code works perfectly under the same circumstances, and under PyQt5 other functions work well.
Trying random things, I just discovered that if I change the code to:
query = QSqlQuery("select * from my table")
model = QSqlTableModel(self)
model.setQuery(query)it works, though if I want to write the changes back to the database I'd have to rewrite the rest of the code... I'd rather use the WidgetMapper. If I execute a INSERT through a QSqlQuery works perfectly, so it's not a problem of permissions or malformed queries.
I'm begining to think I've hit a bug in PyQt, but I can't find any valuable information. The backtrace only tells me that the program was halted while running the "setTable" line... could you point me in the right direction to debug this?
-
Can you do a quick check of your current Qt 5 with a small C++ test application ? That way we can rule out whether it's Qt or PyQt at fault
-
Sorry, I've been pretty busy these days and looks like I'll be for a while, I'll get to it whenever I get some free time. Also, I've run into another problem, this time with the QtPrintSupport module, what it prints using Qt5 is completely different to what it prints in Qt4, among other things it completely ignores the margins settings, but right now I can't get to it. Thanks anyway!