[PyQt] QSqlTableModel.beforeInsert signal (new style signal/slot)

Phil Thompson phil at riverbankcomputing.com
Fri Dec 3 15:06:50 GMT 2010


On Fri, 3 Dec 2010 15:46:55 +0100, "KONTRA, Gergely" <pihentagy at gmail.com>
wrote:
> Hi!
> 
> I am trying to connect the beforeInsert signal of a QSqlTableModel,
> and having some problems.
> 
> I've found this similar thread:
> http://www.mail-archive.com/pyqt@riverbankcomputing.com/msg20117.html
> 
> However, I am using pyqt with py3k, so I prefer the new style signal
> and slots, but I appreciate any working solution...
> 
> So my attempt based on the thread:
> class BatteryMain(base_class, form_class):
>        # ...
>        def cycle_started(self, record):
>                print("Inserting {!r}".format(record))
> 
>        def battery_load(self, filename):
>                self.cycles_model = QSqlTableModel(db=self.battery_db)
>                self.connect(self.cycles_model,
> SIGNAL("beforeInsert(QSqlRecord
> &)"), self.cycle_started)
> 
> RESULT:
> QObject::connect: Cannot queue arguments of type 'QSqlRecord&'
> (Make sure 'QSqlRecord&' is registered using qRegisterMetaType().)
> 
> Another attempt with new style signals and slots:
> 
> class BatteryMain(base_class, form_class):
>        # ...
>        @pyqtSlot('QSqlRecord &')
>        def cycle_started(self, record):
>                print("Inserting {!r}".format(record))
> 
>        def battery_load(self, filename):
>                self.cycles_model = QSqlTableModel(db=self.battery_db)
>               
self.cycles_model.beforeInsert.connect(self.cycle_started)
> 
> RESULT:
>  File "D:\prg\biQazo\biQazo.py", line 145, in battery_load
>    self.cycles_model.beforeInsert.connect(self.cycle_started)
> TypeError: connect() failed between beforeInsert(QSqlRecord) and
unislot()
> 
> Could anybody tell me the correct syntax, please?

It's not a syntax problem.

Are you using threads?

I would guess that you can't use signals that take a QSqlRecord across
threads, probably because they are not passed as const (to allow them to be
updated by a connected slot).

Phil


More information about the PyQt mailing list