QSharedPointer<const QObject> results in compiler errors when used in metatyping (Q_DECLARE_METATYPE)
-
I am currently porting Qt 5 to Qt 6 using Visual Studio 2022 and run into compiler errors.
When using QSharedPointer to a const object that is derived from QObject the metatyping is trying to register a conversion from const to non-const. This looks to me as a Bug in Qt but I couldn't find an issue and I am not sure if some compiler settings are wrong.
A minimal example:
Q_DECLARE_METATYPE(QSharedPointer<const QObject>);
I know that there is no need to explicitly declare this but this is the minimal example to run into this situation
The error message:
1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(1196,1): error C2440: 'return': cannot convert from 'T *' to 'QObject *' 1> with 1> [ 1> T=const QObject 1> ] 1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(1196,32): message : Conversion loses qualifiers 1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(1195): message : while compiling class template member function 'QObject *QtPrivate::QSmartPointerConvertFunctor<QSharedPointer<const QObject>>::operator ()(const SmartPointer &) const' 1> with 1> [ 1> SmartPointer=QSharedPointer<const QObject> 1> ] 1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(613): message : see reference to function template instantiation 'QObject *QtPrivate::QSmartPointerConvertFunctor<QSharedPointer<const QObject>>::operator ()(const SmartPointer &) const' being compiled 1> with 1> [ 1> SmartPointer=QSharedPointer<const QObject> 1> ] 1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(1579): message : see reference to class template instantiation 'QtPrivate::QSmartPointerConvertFunctor<QSharedPointer<const QObject>>' being compiled 1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(1579): message : while compiling class template member function 'bool QtPrivate::MetaTypeSmartPointerHelper<T,void>::registerConverter(void)' 1> with 1> [ 1> T=QSharedPointer<const QObject> 1> ] 1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(1233): message : see reference to function template instantiation 'bool QtPrivate::MetaTypeSmartPointerHelper<T,void>::registerConverter(void)' being compiled 1> with 1> [ 1> T=QSharedPointer<const QObject> 1> ] 1>E:\ExternalLibs\windows_vs17_x64-Qt-6.2.3_r41935\include\QtCore/qmetatype.h(1233): message : see reference to class template instantiation 'QtPrivate::MetaTypeSmartPointerHelper<T,void>' being compiled 1> with 1> [ 1> T=QSharedPointer<const QObject> 1> ] 1>E:\Tests_Lib_Integration\Src\Libs\Basics\Basics\Array1d.cpp(17): message : see reference to function template instantiation 'int qRegisterNormalizedMetaType<QSharedPointer<const QObject>>(const QByteArray &)' being compiled
Qt version: 6.2.3
Visual Studio: 17.0.7 (2022 LTSC 17.0)
Compiler Options:/permissive- /Yu"Basics/Precompiled.h" /GS /W3 /Zc:wchar_t /Gm- /Od /Ob0 /FI"Basics/Precompiled.h" /Zc:inline /fp:precise /D "_UNICODE" /D "UNICODE" /D "_ENABLE_EXTENDED_ALIGNED_STORAGE" /D "QT_GUI_LIB" /D "QT_WIDGETS_LIB" /D "QT_PRINTSUPPORT_LIB" /D "QT_XML_LIB" /D "QT_NETWORK_LIB" /D "QT_TESTLIB_LIB" /errorReport:prompt /WX- /Zc:forScope /RTC1 /GR /Gd /MDd /openmp /std:c++17 /EHa /diagnostics:column
Is there something wrong with my setup?
Am I the only one using QSharedPointer to const object with signal/slot? -
@Franz-Hirschbeck said in QSharedPointer<const QObject> results in compiler errors when used in metatyping (Q_DECLARE_METATYPE):
Is there something wrong with my setup?
Yes, but not syntax-wise.
Am I the only one using QSharedPointer to const object with signal/slot?
QSharedPointer
doesn't really make any sense here, as you're reference counting (externally) an object, that is never supposed to be detached (copied). What should be the purpose of having aQSharedPointer
instead of sayconst QObject *
?Edit: Well, I'd missed that this is an old-ish topic when I replied