[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-bindings
Subject: [Kde-bindings] branches/KDE/4.4/kdebindings/csharp/qyoto/core
From: Arno Rehn <kde () arnorehn ! de>
Date: 2010-02-10 22:41:57
Message-ID: 1265841717.192989.3624.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1088476 by arnorehn:
Fix handling of non-Qt types in QVariant.
CCMAIL: kde-bindings@kde.org
M +17 -2 QVariantExtras.cs
--- branches/KDE/4.4/kdebindings/csharp/qyoto/core/QVariantExtras.cs #1088475:1088476
@@ -78,15 +78,22 @@
typeName = SmokeMarshallers.SmokeClassName(typeof(T));
else
typeName = typeof(T).ToString();
- if (NameToType(typeName) > TypeOf.LastCoreType) {
+ TypeOf type = NameToType(typeName);
+ if (type > TypeOf.LastCoreType) {
IntPtr instancePtr = QVariantValue(typeName, (IntPtr) \
GCHandle.Alloc(this)); return (T) ((GCHandle) instancePtr).Target;
+ } else if (type == TypeOf.Invalid) {
+ Console.WriteLine("QVariant.Value<{0}>(): invalid type", \
typeof(T)); }
return (T) (object) default(T);
}
}
+ static public QVariant FromValue<T>(T value) {
+ return FromValue<T>((object) value);
+ }
+
static public QVariant FromValue<T>(object value) {
if (typeof(T) == typeof(bool)) {
return new QVariant((bool) value);
@@ -148,11 +155,19 @@
typeName = SmokeMarshallers.SmokeClassName(typeof(T));
else
typeName = typeof(T).ToString();
- if (NameToType(typeName) > TypeOf.LastCoreType) {
+ TypeOf type = NameToType(typeName);
+ if (type == TypeOf.Invalid) {
+ // user type, not yet registered
+ QMetaType.RegisterType<T>();
+ type = NameToType(typeName);
+ }
+ if (type > TypeOf.LastCoreType) {
GCHandle handle = (GCHandle) \
QVariantFromValue(QMetaType.type(typeName), (IntPtr) GCHandle.Alloc(value)); \
QVariant v = (QVariant) handle.Target; handle.Free();
return v;
+ } else if (type == TypeOf.Invalid) {
+ throw new Exception("Failed to register type " + \
typeof(T).ToString()); }
return new QVariant();
_______________________________________________
Kde-bindings mailing list
Kde-bindings@kde.org
https://mail.kde.org/mailman/listinfo/kde-bindings
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic