15 #include <QJsonDocument>
16 #include <QJsonObject>
27 if ( nType == qMetaTypeId<QFileInfo>() )
28 return QVariant::fromValue< QFileInfo >( *((QFileInfo *)pValue) );
30 if (nType > QMetaType::User)
32 QObject *pObj = *((QObject **)pValue);
34 return QVariant::fromValue<QObject*>( pObj );
37 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
38 return { nType, pValue };
40 return QVariant( QMetaType(nType), pValue );
50 const QString &sParamType,
52 const QString &sValue )
59 case QMetaType::Bool : *((
bool *)pParam) =
ToBool( sValue );
break;
61 case QMetaType::Char : *((
char *)pParam) = ( sValue.length() > 0) ? sValue.at( 0 ).toLatin1() : 0;
break;
62 case QMetaType::UChar : *((
unsigned char *)pParam) = ( sValue.length() > 0) ? sValue.at( 0 ).toLatin1() : 0;
break;
63 case QMetaType::QChar : *(( QChar *)pParam) = ( sValue.length() > 0) ? sValue.at( 0 ) : QChar(0);
break;
65 case QMetaType::Short : *((
short *)pParam) = sValue.toShort ();
break;
66 case QMetaType::UShort : *(( ushort *)pParam) = sValue.toUShort ();
break;
68 case QMetaType::Int : *((
int *)pParam) = sValue.toInt ();
break;
69 case QMetaType::UInt : *((
uint *)pParam) = sValue.toUInt ();
break;
71 case QMetaType::Long : *((
long *)pParam) = sValue.toLong ();
break;
72 case QMetaType::ULong : *(( ulong *)pParam) = sValue.toULong ();
break;
74 case QMetaType::LongLong : *(( qlonglong *)pParam) = sValue.toLongLong ();
break;
75 case QMetaType::ULongLong : *(( qulonglong *)pParam) = sValue.toULongLong ();
break;
77 case QMetaType::Double : *((
double *)pParam) = sValue.toDouble ();
break;
78 case QMetaType::Float : *((
float *)pParam) = sValue.toFloat ();
break;
80 case QMetaType::QString : *(( QString *)pParam) = sValue;
break;
81 case QMetaType::QByteArray : *(( QByteArray *)pParam) = sValue.toUtf8 ();
break;
83 case QMetaType::QDateTime :
86 dt.setTimeSpec( Qt::UTC );
87 *(( QDateTime *)pParam) = dt;
92 case QMetaType::QJsonObject :
94 QJsonDocument doc = QJsonDocument::fromJson(sValue.toUtf8());
100 *(( QJsonObject *)pParam) = doc.object();
103 throw QString(
"Invalid JSON: %1").arg(sValue);
113 int nLastIdx = sParamType.lastIndexOf(
"::" );
118 QString sParentFQN = sParamType.mid( 0, nLastIdx );
119 QString sEnumName = sParamType.mid( nLastIdx+2 );
125 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
128 auto *pParentClass = (QObject *)QMetaType::create( nParentId );
129 if (pParentClass ==
nullptr)
132 const QMetaObject *pMetaObject = pParentClass->metaObject();
134 QMetaType::destroy( nParentId, pParentClass );
136 const QMetaObject *pMetaObject =
137 QMetaType::fromName( sParentFQN.toUtf8() ).metaObject();
144 int nEnumIdx = pMetaObject->indexOfEnumerator( sEnumName.toUtf8());
149 QMetaEnum metaEnum = pMetaObject->enumerator( nEnumIdx );
151 *((
int *)pParam) = metaEnum.keyToValue( sValue.toUtf8() );
165 if (sVal.compare(
"1", Qt::CaseInsensitive ) == 0)
168 if (sVal.compare(
"y", Qt::CaseInsensitive ) == 0)
171 if (sVal.compare(
"true", Qt::CaseInsensitive ) == 0)