[PyKDE] Re: Manipulating a QSqlRecord in a primeInsert handler

Jorge Godoy godoy at ieee.org
Thu Apr 28 16:13:06 BST 2005

Jorge Godoy <godoy at ieee.org> writes:

> Is there something else I should be doing?  Is it the correct way to handle
> this kind of thing to create a new button to get the correct ID and then use
> the 'Insert' button to make the insertion on the database?

OK, answering myself...

Contradicting one of the docs --
http://doc.trolltech.com/3.3/designer-manual-8.html -- but following the Qt
documentation (both should say the same thing, but...) I had to use the
'beforeInsert' handler instead of the 'primeInsert'.  At least with pyQt.  I
don't know if it works correctly with a C++ program, but I suspect it does.
(I suspect why pyQt doesn't work, but I'm not sure.  I think it isn't
expecting a return value and is discarding the changes.  I dunno how to make
it work in the same way -- and scope -- that the C++ version does...)

On the other hand, this brought me a new problem: (py?)Qt decides for itself
what SQL command to generate, no matter what button I click.  If I have some
data on the screen, change it and click 'Insert', it generates an UPDATE SQL
instruction.  If the cursor is positioned in an invalid position, though, the
INSERT SQL instruction is generated correctly.

This causes me a problem because there are redundant actions for both 'Insert'
and 'Update' buttons that are automatically generated by Qt Designer (actually

I'm doing the insertion in two 'superposing' methods: first I position the
cursor in an invalid position with the 'New Record' button I had to add and
then I insert it into the database with the 'Insert' button KDevDesigner
created for me... 

Should I remove the 'Update' button and keep just the 'Insert' one?  Or is
this a bug somewhere?  Should I be doing the insertion in two handlers?  I'll
be "playing" more with this today...

Thanks in advance for any hints,
Jorge Godoy      <godoy at ieee.org>

More information about the PyQt mailing list