kcombobox doc update

Dawit A. adawit at kde.org
Thu Aug 12 05:01:51 BST 2004


On Wednesday 11 August 2004 20:56, George Staikos wrote:
> On Wednesday 11 August 2004 19:57, Dawit A. wrote:
>
>    I wasn't trying to make anything melodramatic.  I just spent time
> debugging a problem which turns out to be because the object returns a
> pointer but deletes that pointer on you apparently without warning.  The
> usage case was this [reduced]:
>
> KCompletion *foo = combo->completionObject();
> combo->setEditable(false);
> foo->clear(); // or anything else

The problem is very simple. When you call setEditable(false), QComboBox 
deletes the lineedit object associated with it. This in turn deletes the 
completion object since it is created by the lineedit and you did not tell 
KComboBox not to delete the completion object, i.e. call 
setAutoDeleteCompletionObject(false). Please note that you will be 
responsible for managing the completion object from then on , i.e. you will 
have to delete it yourself...

BTW, I just want to point out to you that this is behavior no different than

KLineEdit *edit = combo->lineEdit();
como->setEditable(false);
combo->lineEdit()->setText(...); //crash and burn...

Attached is a docu update to warn the unwary about this issue.

> It's really not obvious that this will happen since I never touched the
> completion object in any way between getting a pointer to it and then using
> that pointer.  This crash was reported to me by someone else who also
> probably didn't understand why it was crashing.
>
> > > Note: this is a very confusing API/object!
> >
> > Thanks...
>
>   Sorry, the completion stuff really is confusing.

George, I know. It got more complicated as QComobBox's API changed (read: 
added new methods). If I had to do it again, I would not have opted to use a 
composition or some other means instead of inheriting from KCompletionBase. 
Anyways, that is neither here nor there and obviously off topic. There is 
always KDE 4.x to improve things if necessary...

-- 
Regards,
Dawit A.
"Preach what you practice, practice what you preach"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kcombobox-doc-update.diff
Type: text/x-diff
Size: 1776 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040812/ef3580f4/attachment.diff>


More information about the kde-core-devel mailing list