[Development] Updating holdover API from Qt 1 times

Mutz, Marc marc at kdab.com
Sat Aug 17 14:45:31 CEST 2019


On 2019-08-17 07:13, Sze Howe Koh wrote:
[...]
> Which should we implement? I personally prefer (2) as it it can be
> added to Qt 5.x and provides backward compatibility while keeping the
> nice compact function names. We could enable QT_NO_COW by default in
> Qt 6.5 LTS and then remove the old function and Qt::ReturnByValue_t in
> Qt 7.0.
> 
> I'm not sure I like the verbosity or SiC-ness of std::optional, hence
> I'm asking for thoughts here.
[...]

Which one is more SiC?

old:

    QPixmap *pm = label->pixmap();
    if (pm)
        use(*pm);

with (2):

    QPixmap pm = label->-pixmap();
    if (!pm.isNull())
        use(pm);

with optional<>:

    std::optional<QPixmap> pm = label->pixmap();
    if (pm)
        use(*pm);

old, using auto:

    auto pm = label->pixmap();
    if (pm)
        use(*pm);

(2), using auto:

    auto pm = label->pixmap();
    if (!pm.isNull())
        use(pm);

optional<>, with auto:

    auto pm = label->pixmap();
    if (pm)
        use(*pm);

To me, that looks like optional<> with auto is SC while (2) is SiC with 
or without auto.

Seeing as auto will also have to be the solution for code that wants to 
stay compatible between Qt 5 and 6 when it comes with QList, I don't 
think anything but optional<> passes muster.

Thanks,
Marc



More information about the Development mailing list