json: Qt6: Break changes
I have a large Qt C++ application that’s uses this nlohmann json
library everywhere.
Well, Qt has release the new Qt6 version in this week.
So I just switch from Qt 5.15.0 to the Qt6 and tried to compile my C++ project and I got some compile time warnings and errors related with nlohmann json
library.
Warning message 1:
/home/nyck/Qt6/6.0.0/gcc_64/include/QtCore/qglobal.h:1126: warning: ‘void QtPrivate::warnIfContainerIsNotShared(...) [with T = std::__cxx11::list<QString>]’ is deprecated: Do not use foreach/Q_FOREACH with containers which are not implicitly shared. Prefer using a range-based for loop with these containers: `for (const auto &it : container)`, keeping in mind that range-based for doesn't copy the container as Q_FOREACH does [-Wdeprecated-declarations]
In file included from ../../../../Qt6/6.0.0/gcc_64/include/QtGui/qtguiglobal.h:43,
from ../../../../Qt6/6.0.0/gcc_64/include/QtWidgets/qtwidgetsglobal.h:43,
from ../../../../Qt6/6.0.0/gcc_64/include/QtWidgets/qmainwindow.h:43,
from ../../../../Qt6/6.0.0/gcc_64/include/QtWidgets/QMainWindow:1,
from ../../rotortest/App/app.h:4,
from ../../rotortest/App/app.cpp:1:
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qglobal.h: In instantiation of ‘QtPrivate::QForeachContainer<typename std::decay<_Tp>::type> QtPrivate::qMakeForeachContainer(T&&) [with T = const std::__cxx11::list<QString>&; typename std::decay<_Tp>::type = std::__cxx11::list<QString>]’:
../../rotortest/App/app.cpp:320:5: required from here
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qglobal.h:1126:61: warning: ‘void QtPrivate::warnIfContainerIsNotShared(...) [with T = std::__cxx11::list<QString>]’ is deprecated: Do not use foreach/Q_FOREACH with containers which are not implicitly shared. Prefer using a range-based for loop with these containers: `for (const auto &it : container)`, keeping in mind that range-based for doesn't copy the container as Q_FOREACH does [-Wdeprecated-declarations]
1126 | warnIfContainerIsNotShared<typename std::decay<T>::type>(0);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qglobal.h:1120:13: note: declared here
1120 | inline void warnIfContainerIsNotShared(...) {}
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
Error message 1:
/usr/include/c++/9/type_traits:131: error: incomplete type ‘QTypeTraits::detail::expand_operator_equal_container<nlohmann::basic_json<>, true>’ used in nested name specifier
In file included from /usr/include/c++/9/bits/move.h:55,
from /usr/include/c++/9/bits/stl_pair.h:59,
from /usr/include/c++/9/bits/stl_algobase.h:64,
from /usr/include/c++/9/memory:62,
from moc_form_pipeline.cpp:9:
/usr/include/c++/9/type_traits: In instantiation of ‘struct std::__and_<QTypeTraits::detail::expand_operator_equal_container<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, true>, QTypeTraits::detail::expand_operator_equal_tuple<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > > >’:
/usr/include/c++/9/type_traits:155:12: required from ‘struct std::conjunction<QTypeTraits::detail::expand_operator_equal_container<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, true>, QTypeTraits::detail::expand_operator_equal_tuple<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > > >’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qtypeinfo.h:260:8: required from ‘struct QTypeTraits::detail::expand_operator_equal_container<nlohmann::basic_json<>, true>’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qtypeinfo.h:324:8: required from ‘struct QTypeTraits::has_operator_equal<nlohmann::basic_json<> >’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qtypeinfo.h:326:23: required from ‘constexpr const bool QTypeTraits::has_operator_equal_v<nlohmann::basic_json<> >’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qmetatype.h:2123:67: required from ‘constexpr const QtPrivate::QMetaTypeInterface QtPrivate::QMetaTypeInterfaceWrapper<nlohmann::basic_json<> >::metaType’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qmetatype.h:2377:16: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = qt_meta_stringdata_Form_Pipeline_t; TypeCompletePair = QtPrivate::TypeAndForceComplete<const nlohmann::basic_json<>&, std::integral_constant<bool, false> >]’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qmetatype.h:2421:55: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_incomplete_metaTypeArray [14]<qt_meta_stringdata_Form_Pipeline_t, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >&, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const QString&, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const MSG_TYPE, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const QString&, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> > >’
moc_form_pipeline.cpp:155:1: required from here
/usr/include/c++/9/type_traits:131:12: error: incomplete type ‘QTypeTraits::detail::expand_operator_equal_container<nlohmann::basic_json<>, true>’ used in nested name specifier
131 | struct __and_<_B1, _B2>
| ^~~~~~~~~~~~~~~~
Error message 2:
/usr/include/c++/9/type_traits:131: error: incomplete type ‘QTypeTraits::detail::expand_operator_less_than_container<nlohmann::basic_json<>, true>’ used in nested name specifier
In file included from /usr/include/c++/9/bits/move.h:55,
from /usr/include/c++/9/bits/stl_pair.h:59,
from /usr/include/c++/9/bits/stl_algobase.h:64,
from /usr/include/c++/9/memory:62,
from moc_form_pipeline.cpp:9:
/usr/include/c++/9/type_traits: In instantiation of ‘struct std::__and_<QTypeTraits::detail::expand_operator_less_than_container<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, true>, QTypeTraits::detail::expand_operator_less_than_tuple<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > > >’:
/usr/include/c++/9/type_traits:155:12: required from ‘struct std::conjunction<QTypeTraits::detail::expand_operator_less_than_container<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >, true>, QTypeTraits::detail::expand_operator_less_than_tuple<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > > > >’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qtypeinfo.h:296:8: required from ‘struct QTypeTraits::detail::expand_operator_less_than_container<nlohmann::basic_json<>, true>’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qtypeinfo.h:329:8: required from ‘struct QTypeTraits::has_operator_less_than<nlohmann::basic_json<> >’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qtypeinfo.h:331:23: required from ‘constexpr const bool QTypeTraits::has_operator_less_than_v<nlohmann::basic_json<> >’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qmetatype.h:2139:71: required from ‘constexpr const QtPrivate::QMetaTypeInterface QtPrivate::QMetaTypeInterfaceWrapper<nlohmann::basic_json<> >::metaType’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qmetatype.h:2377:16: required from ‘constexpr const QtPrivate::QMetaTypeInterface* QtPrivate::qTryMetaTypeInterfaceForType() [with Unique = qt_meta_stringdata_Form_Pipeline_t; TypeCompletePair = QtPrivate::TypeAndForceComplete<const nlohmann::basic_json<>&, std::integral_constant<bool, false> >]’
../../../../Qt6/6.0.0/gcc_64/include/QtCore/qmetatype.h:2421:55: required from ‘constexpr const QtPrivate::QMetaTypeInterface* const qt_incomplete_metaTypeArray [14]<qt_meta_stringdata_Form_Pipeline_t, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator<unsigned char> > >&, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const QString&, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const MSG_TYPE, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<const QString&, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> >, QtPrivate::TypeAndForceComplete<void, std::integral_constant<bool, false> > >’
moc_form_pipeline.cpp:155:1: required from here
/usr/include/c++/9/type_traits:131:12: error: incomplete type ‘QTypeTraits::detail::expand_operator_less_than_container<nlohmann::basic_json<>, true>’ used in nested name specifier
131 | struct __and_<_B1, _B2>
| ^~~~~~~~~~~~~~~~
What can I do? How to fix it?
Thank you,
My system:
- Ubuntu 20.04 x64
- Qt 5.15.0 and Qt 6.0.0
- nlohmann JSON version 3.8.0
- Qt Creator IDE 4.13.3
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (9 by maintainers)
Sorry…my mistake!
In my
CMakeLists.txt
I was linking always with Qt5… You can close this issue now!You need one separate header file with template specializations (and also with guards, of course). Include this separate header wherever you include
nlohmann/json.hpp
along with Qt headers. No other file should contain the specializations themselves. The header you can take here: nlohmann_json_qt6_hack.h