Skip to content

Commit

Permalink
qt6: Handle some QMetatype changes. (1)
Browse files Browse the repository at this point in the history
Add conditional code to handle the changes to the following functions
in Qt6. The new code is taken from the qt6 qmetatype.h header file.

    QMetaType::type
    QMetaType::typeFlags
    QMetaType::typeName
    QMetaType::metaObjectForType
  • Loading branch information
linuxdude42 committed Dec 8, 2021
1 parent 8c19737 commit 282f38b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
30 changes: 27 additions & 3 deletions mythtv/libs/libmythbase/http/mythhttpmetamethod.cpp
Expand Up @@ -91,7 +91,11 @@ MythHTTPMetaMethod::MythHTTPMetaMethod(int Index, QMetaMethod& Method, int Reque
// Add type/value for each method parameter
for (int i = 0; i < names.size(); ++i)
{
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
int type = QMetaType::type(types[i]);
#else
int type = QMetaType::fromName(types[i]).id();
#endif

// Discard methods that use unsupported parameter types.
// Note: slots only - these are supportable for signals
Expand Down Expand Up @@ -127,16 +131,30 @@ HTTPMethodPtr MythHTTPMetaMethod::Create(int Index, QMetaMethod &Method, int Req
void* MythHTTPMetaMethod::CreateParameter(void* Parameter, int Type, const QString& Value)
{
// Enum types
if (auto typeflags = QMetaType::typeFlags(Type); (typeflags & QMetaType::IsEnumeration) == QMetaType::IsEnumeration)
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
auto typeflags = QMetaType::typeFlags(Type);
#else
auto typeflags = QMetaType(Type).flags();
#endif
if ((typeflags & QMetaType::IsEnumeration) == QMetaType::IsEnumeration)
{
// QMetaEnum::keyToValue will return -1 for an unrecognised enumerant, so
// default to -1 for all error cases
int value = -1;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
QByteArray type = QMetaType::typeName(Type);
#else
QByteArray type = QMetaType(Type).name();
#endif
if (int index = type.lastIndexOf("::" ); index > -1)
{
QString enumname = type.mid(index + 2);
if (const auto * metaobject = QMetaType::metaObjectForType(Type); metaobject)
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const auto * metaobject = QMetaType::metaObjectForType(Type);
#else
const auto * metaobject = QMetaType(Type).metaObject();
#endif
if (metaobject)
{
int enumindex = metaobject->indexOfEnumerator(enumname.toUtf8());
if (enumindex >= 0)
Expand Down Expand Up @@ -190,7 +208,13 @@ QVariant MythHTTPMetaMethod::CreateReturnValue(int Type, void* Value)

// This assumes any user type will be derived from QObject...
// (Exception for QFileInfo)
if (Type == QMetaType::type("QFileInfo"))
if (
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
Type == QMetaType::type("QFileInfo")
#else
Type == QMetaType::fromName("QFileInfo").id()
#endif
)
return QVariant::fromValue<QFileInfo>(*(static_cast<QFileInfo*>(Value)));

if (Type > QMetaType::User)
Expand Down
12 changes: 12 additions & 0 deletions mythtv/libs/libmythbase/http/mythwsdl.cpp
Expand Up @@ -323,7 +323,11 @@ QDomElement MythWSDL::CreateBindingOperation( QString path, HTTPMethodPtr handle
oDirection.appendChild( oNode );
oOp.appendChild( oDirection );

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const char * typeName = QMetaType::typeName(handler->m_types[0]);
#else
const char * typeName = QMetaType(handler->m_types[0]).name();
#endif

if (QString::compare(typeName, "void", Qt::CaseInsensitive ) != 0)
{
Expand Down Expand Up @@ -390,7 +394,11 @@ QDomElement MythWSDL::CreateMethodType( HTTPMethodPtr handler,
QDomElement oNode = createElement( "xs:element" );

// QString sType = oInfo.m_oMethod.typeName();
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const char * typeName = QMetaType::typeName(handler->m_types[0]);
#else
const char * typeName = QMetaType(handler->m_types[0]).name();
#endif

QString sType(typeName);
// if (sType.startsWith("V2"))
Expand Down Expand Up @@ -439,7 +447,11 @@ QDomElement MythWSDL::CreateMethodType( HTTPMethodPtr handler,
{
auto name = handler->m_names[count];
paramNames.append(name.toUtf8());
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
const char * typeName = QMetaType::typeName(handler->m_types[count]);
#else
const char * typeName = QMetaType(handler->m_types[count]).name();
#endif
paramTypes.append(QByteArray(typeName));
}

Expand Down

0 comments on commit 282f38b

Please sign in to comment.