[Qt-interest] qobject_cast<> questions
Karol Krizka
kkrizka at gmail.com
Sun May 31 14:59:20 CEST 2009
On Sun, May 31, 2009 at 10:42 AM, Ross Bencina
<rossb-lists at audiomulch.com> wrote:
> Karol Krizka wrote:
>>>
>>> Testing the actual behavior tells me nothing about the specified,
>>> expected
>>> or required behavior. I hope that you guys do more than "check the source
>>> code" to determine how such fundamental mechanisms as a type safe dynamic
>>> cast are supposed to behave.
>>>
>> What is wrong with checking the source code?
>
> Hi Karol, thanks for asking... <grin>
>
> What is wrong is that the source code is not a contract, it is an
> implementation of a contract. If you want to know how dynamic_cast is
> expected to behave in std C++ do you look at the gcc source code (or in the
> msvc source code for that matter) or do you look it up in the C++ language
> specification?
>
> Another answer to your question is: How do I know the source code is correct
> if the expected behavior is unspecified? Perhaps someone might remove that
> null pointer check in the future -- based on the current documentation that
> would be a great optimisation.
>
> I have used Qt long enough to know that how things are supposed to work is
> not always how they work. If we were talking about some widget detail (like
> the QTableView discussion recently) I would probably check out the source
> code -- but qobject_cast isn't some (relatively) vaguely specified widget,
> it's a fundamental language mechanism whose behavior in an important case is
> not currently specified.
>
> What I could do, is search the entire Qt sourcebase and see how much other
> Qt code depends on qobject_cast supporting a null parameter -- that would be
> a _relatively_ safe bet, but not as safe as seeking out a definitive answer
> and having the specification (documentation) updated accordingly. As a
> paying customer I expect and demand a level of quality engineering from Qt
> Software that goes beyond "just check the source code."
>
Ah, I think that is the core difference between you and me. You're
paying for the commercial license, so you probably expect Qt to be of
certain quality and work without breakage for a longer time. I, on the
other hand, am using the open source license, so I have the will and
time to go digging and fix bugs. ;)
Also I don't view qobject_cast to be on the same level of being
"fundamental" as dynamic_cast. I view qobject_cast to be more of a
helper function that does the same thing as static_cast (I looked),
but also checks that the QObject can be cast to the specified object.
I'm not a compiler expert, so I might be wrong, but it seems to me
that dynamic_cast is more than a few if statements. But that is just
my opinion.
--
Cheers,
Karol Krizka
http://www.krizka.net
More information about the Qt-interest-old
mailing list