[Interest] QSharedDataPointer detach too much ( don't call const )
Michal Lazo
xlazom00 at gmail.com
Thu Sep 20 12:43:07 CEST 2018
"So my whole C++ world just changed."
Can you point me to right article in C++ documentation ?
So Qt devs I found some code for example
http://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/text/qtextcursor.cpp#n1151
And it looks like it should be better to call const variant
what do you think ??
And there is more code like this.
On Thu, Sep 20, 2018 at 11:28 AM Philippe <philwave at gmail.com> wrote:
> This is a (logical) C++ aspect, not a Qt thing:
> non-constant pointers call non-contant methods in priority.
>
> Philippe
>
> On Thu, 20 Sep 2018 11:02:44 +0200
> Michal Lazo <xlazom00 at gmail.com> wrote:
>
>
> I still don't see reason why compiler don't call const variants to access
> raw pointer
>
> http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qshareddata.h#n76
>
> for example here(QTextCursor)
>
> http://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/text/qtextcursor.cpp#n1151
> I would expect calling const variant and I think that author of that lines
> expect same.
>
> On Thu, Sep 20, 2018 at 10:55 AM Philippe <philwave at gmail.com> wrote:
>
>> You just have to change your line:
>>
>> Car * carPtr = &car;
>> with
>>
>> *const* Car * carPtr = &car;
>> Philippe
>>
>> On Thu, 20 Sep 2018 10:40:01 +0200
>> Michal Lazo <xlazom00 at gmail.com> wrote:
>>
>>
>>
>> Hello
>> example
>> https://pastebin.com/xL9yWhKe
>>
>> I never used QSharedDataPointer in my code but is is heavily used in Qt
>> My problem is that I found that QSharedDataPointer prefer non const
>> operator for access raw pointer to object instead of const variant.
>> And at the end non const variant call detach() = cloning object
>> Look at my example and plz debug if conditions
>>
>> I use compiler MSVC 2015, 2017
>>
>> My problem is that for example QTextCursor use this constructions and it
>> heavily call detach. And simple call const variant of method should fix
>> this.
>>
>> Anybody can explain this behaviour?
>>
>>
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180920/e58cecc8/attachment.html>
More information about the Interest
mailing list