[Kde-bindings] [qtruby] /: * Fix bug in Qt::Variant#value where it as failing for ushort and QChar

Richard Dale richard.dale at telefonica.net
Wed Apr 11 12:25:32 UTC 2012


Git commit cf0f2cf1ac2294f68ba270cfce309b54f0bab38d by Richard Dale.
Committed on 11/04/2012 at 14:24.
Pushed by rdale into branch 'master'.

* Fix bug in Qt::Variant#value where it as failing for ushort and QChar
variants. Thanks to Yaohan Chen for reporting the bug

CCMAIL: kde-bindings at kde.org

M  +5    -0    ChangeLog
M  +15   -1    src/qtruby.cpp

http://commits.kde.org/qtruby/cf0f2cf1ac2294f68ba270cfce309b54f0bab38d

diff --git a/ChangeLog b/ChangeLog
index 103a0b1..0fe6fd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-04-11  Richard Dale  <richard.j.dale at gmail.com>
+
+	* Fix bug in Qt::Variant#value where it as failing for ushort and QChar
+	variants. Thanks to Yaohan Chen for reporting the bug
+
 2012-04-09  Richard Dale  <richard.j.dale at gmail.com>
 
     * Rename rb_str_catf() as qtruby_str_catf() as it clashes with a function
diff --git a/src/qtruby.cpp b/src/qtruby.cpp
index f405ba5..a60e424 100644
--- a/src/qtruby.cpp
+++ b/src/qtruby.cpp
@@ -1044,6 +1044,17 @@ qvariant_value(VALUE /*self*/, VALUE variant_value_klass, VALUE variant_value)
 	} else if (variant->type() >= QVariant::UserType) {
 		// If the QVariant contains a user type, don't bother to look at the Ruby class argument
 		value_ptr = QMetaType::construct(QMetaType::type(variant->typeName()), (void *) variant->constData());
+
+		if (qstrcmp(variant->typeName(), "uchar") == 0) {
+			return UINT2NUM(*reinterpret_cast<uchar*>(value_ptr));
+		} else if (qstrcmp(variant->typeName(), "char") == 0) {
+			return INT2NUM(*reinterpret_cast<char*>(value_ptr));
+		} else if (qstrcmp(variant->typeName(), "ushort") == 0) {
+			return UINT2NUM(*reinterpret_cast<ushort*>(value_ptr));
+		} else if (qstrcmp(variant->typeName(), "short") == 0) {
+			return INT2NUM(*reinterpret_cast<short*>(value_ptr));
+		}
+
 		Smoke::ModuleIndex mi = o->smoke->findClass(variant->typeName());
 		vo = alloc_smokeruby_object(true, mi.smoke, mi.index, value_ptr);
 		return set_obj_info(qtruby_modules[mi.smoke].binding->className(mi.index), vo);
@@ -1055,7 +1066,10 @@ qvariant_value(VALUE /*self*/, VALUE variant_value_klass, VALUE variant_value)
 		return Qnil;
 	}
 
-	if (qstrcmp(classname, "Qt::Pixmap") == 0) {
+	if (qstrcmp(classname, "Qt::Char") == 0) {
+		QChar v = qVariantValue<QChar>(*variant);
+		value_ptr = (void *) new QChar(v);
+	} else if (qstrcmp(classname, "Qt::Pixmap") == 0) {
 		QPixmap v = qVariantValue<QPixmap>(*variant);
 		value_ptr = (void *) new QPixmap(v);
 	} else if (qstrcmp(classname, "Qt::Font") == 0) {


More information about the Kde-bindings mailing list