<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"><html><head><meta name="qrichtext" content="1" /><style type="text/css">p, li { white-space: pre-wrap; }</style></head><body style=" font-family:'Consolas'; font-size:11pt; font-weight:400; font-style:normal;">On Sunday 13 July 2008, Rafael Fernández López wrote:<br>
> Hi,<br>
><br>
> > You could then have a non-virtual function in KAbstractFileWidget whose<br>
> > implementation packages up the parameters for virtual_hook() and then<br>
> > calls virtual_hook(). Subclasses would then have to reimplement<br>
> > virtual_hook() if they needed to change the behavior though so it may not<br>
> > be the best way I guess if there's an easier way.<br>
><br>
> Cool !! Didn't notice it ! The question now is, does it need to be virtual<br>
> ?<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>A class's implementation does not need to be but you would need to redefine virtual_hook() in the subclass if a different implementation is desired:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>i.e.: (2 space shiftwidth for email purposes)<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>void KAbstractFileWidget::setConfirmOverride(bool b)<br>
{<br>
virtual_hook(0, static_cast<void*>(&b)); // 0 is id of call<br>
}<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>Now in a subclass:<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>void KFileWidget::virtual_hook(int id, void *data)<br>
{<br>
if(id == 0) // setConfirmOverride(bool)<br>
{<br>
bool *b = static_cast<bool*>(data);<br>
setConfirmOverrideInternal(b); // not virtual<br>
}<br>
else<br>
{<br>
// Unhandled, pass it to superclass.<br>
KAbstractFileWidget::virtual_hook(id, data);<br>
}<br>
}<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>Since the implementation is done in virtual_hook, and KAbstractFileWidget::setConfirmOverride() calls virtual_hook(), the right virtual implementation will always get called. KFileWidget's implementation could be changed by handling virtual_hook() in a subclass.<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>Now if for whatever reason you override setConfirmOverride() in a subclass you would need to ensure calling virtual_hook() as setConfirmOverride() cannot be virtual, but there's really no reason to override setConfirmOverride in a subclass, the reimplementation belongs in virtual_hook().<br>
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; -qt-user-state:0;"></p>Regards,<br>
- Michael Pyne</p></body></html>