[Development] Should qMetaTypeId<const T>() == qMetaTypeId<T>()?

Jedrzej Nowacki Jedrzej.Nowacki at qt.io
Wed Aug 31 10:00:53 CEST 2016


I love to be proven wrong, but this time I would not call it easy [?]  Try this:


struct F{};
Q_DECLARE_METATYPE(F*);
Q_DECLARE_METATYPE(const F*);
Q_DECLARE_METATYPE(F);
// Q_DECLARE_METATYPE(const F); doesn't compile, that is a bug!

class O : public QObject
{
    Q_OBJECT
signals:
    void foo1(const F*);
    void foo2(F*);
};

int main(int argc, char **argv) {
    qDebug() << QMetaMethod::fromSignal(&O::foo1).methodSignature();
    qDebug() << QMetaMethod::fromSignal(&O::foo2).methodSignature();
    return 0;
}



________________________________
From: Development <development-bounces+jedrzej.nowacki=qt.io at qt-project.org> on behalf of Olivier Goffart <olivier at woboq.com>
Sent: Saturday, August 27, 2016 9:30:21 AM
To: development at qt-project.org
Subject: Re: [Development] Should qMetaTypeId<const T>() == qMetaTypeId<T>()?

On Mittwoch, 24. August 2016 16:06:50 CEST J?drzej Nowacki wrote:
> On onsdag 24. august 2016 15.23.01 CEST Marc Mutz wrote:
> > Hi,
> >
> > Currently, it's not, which doesn't make much sense, does it?
> >
> > So,
> >
> >   template <typename T>
> >   int qMetyTypeId<T>() {
> >     return qMetaTypeIdHelper<typename std::remove_cv<T>::type>();
> >   }
> > ?
> >
> > (There's of course a lot more involved in this, registration should
> > discard const, too, e.g.).

I think it make sens, but it should be done at the QMetaTypeId2 Level.
We already do this for const T&, See commit
03b25125986f083a260b421abeed1f1d088d27b3
In fact, the same should be done for const T

> From C++ perspective const T and T are kind of separate types, metatype
> mimics that. QMetaType is used in many places and in some constness
> matters.
>
> Consider that example:
>  QMetaType::typeName(qMetaTypeId<const QString>())
> and
>  QMetaType::typeName(qMetaTypeId<QString>())
> The function is used in metaobject to compute signatures of invokables.

I can prove you wrong easily,  both have the same result, since
QMetaType::normalizedType("const QString") == "QString"

They are different C++ type, yes,  but from a practical purpose, their use in
the metatype system is exactly the same.  You allocate, destroy or copy a
const QString the same way you do a QString.

--
Olivier

Woboq - Qt services and support - https://woboq.com - https://code.woboq.org
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20160831/51c63e35/attachment.html>


More information about the Development mailing list