On Fri, 3 Dec 2010 17:19:00 +0100, "KONTRA, Gergely" <pihent...@gmail.com> wrote: > On Fri, Dec 3, 2010 at 16:06, Phil Thompson > <p...@riverbankcomputing.com>wrote: > >> On Fri, 3 Dec 2010 15:46:55 +0100, "KONTRA, Gergely" >> <pihent...@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? >> > > Yes, I am using threads. Is it valid to insert into a QSqlTableModel a new > row in a QThread? > I have a worker thread, which collects data, and inserts it into the > QSqlTableModel, and I'd like to get notified with this beforeInsert signal > in the GUI thread. > >> >> 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). >> > That sounds sad. I thought this signal will make it easy to communicate > between threads. > Then what is the solution to communicate between the worker thread, and the > main GUI thread? Cutsom signal?
Yes, or a custom event (which is how cross-thread signals are handled anyway). Phil _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt