Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. QSharedPointer<const QObject> results in compiler errors when used in metatyping (Q_DECLARE_METATYPE)
Forum Updated to NodeBB v4.3 + New Features

QSharedPointer<const QObject> results in compiler errors when used in metatyping (Q_DECLARE_METATYPE)

Scheduled Pinned Locked Moved Unsolved Qt 6
2 Posts 2 Posters 454 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Franz Hirschbeck
    wrote on last edited by
    #1

    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?

    kshegunovK 1 Reply Last reply
    0
    • F Franz Hirschbeck

      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?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      @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 a QSharedPointer instead of say const QObject *?

      Edit: Well, I'd missed that this is an old-ish topic when I replied

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved