[PyKDE] QSqlEditorFactory.createEditor invocation problem, possibly PyQt bug

Hans-Peter Jansen hpj at urpla.net
Thu Jun 20 17:47:00 BST 2002


On Wed, 19 Jun 2002 18:07:36 +0100
Phil wrote:

> I wrote:
> > The constuctor gets called, but createEditor doesn't. The PyQt docs
> > state, this class is fully implemented, but Boudewijn gave me the
> > hint, that it has two methods with the same name and the same number
> > of arguments. Could it be the problem here?
> 
> createEditor() gets called if I right click and select "Insert". You

Yes, but it's c++ ancestor behaves different in this respect. It 
displays it's editor on double click of the status field. Do you
have an idea, where this difference come from?

> then hit other problems - the following fixes the immediate ones:
> 
>      def createEditor(self, parent, field):
>          print "createEditor:", parent, field
>          try:
>              if str(field.name()) == "statusid":
>                  return StatusPicker(parent)
>          except AttributeError:
>              pass
> 
>          return QSqlEditorFactory.createEditor(self, parent, field)
> 
> You have to be careful because the Python createEditor() re-implements
> all C++ methods of the same name that are in scope. There are two in 
> this case so the code needs to determine which it is supposed to do. In 
> the above I assume it's the one I'm interested in, and handle the 
> exception if it turns out not to be the right one.

Thanks for clarification. Got it. 

> You then hit the bugs in StatusPicker, but they seem to be fairly obvious.

Sorry for my stupidity. Attached is a corrected version, derived from table4
example, because it's more likely, that one want it to do this way.

It reveals another problem. The mapping, handled in StatusPicker.statusId
and setStatusId doesn't work at all. They aren't called either. In the
c++ header of this class, there is an dubious line:

Q_PROPERTY( int statusid READ statusId WRITE setStatusId )

How do we handle this in PyQt?

BTW, on experimenting with right click inserts, I ran into database key errors.
Here is, what I did to fix them:
mysql> use testdb
mysql> alter table staff change id id1 int AUTO_INCREMENT;
mysql> alter table staff change id1 id int AUTO_INCREMENT;

> Phil
 
Hans-Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqltable4.py
Type: application/octet-stream
Size: 4250 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20020620/275e4fda/sqltable4.obj


More information about the PyQt mailing list