[Kde-bindings] KDE/kdebindings/qtruby

Richard Dale Richard_Dale at tipitina.demon.co.uk
Tue May 23 12:08:22 UTC 2006


SVN commit 544018 by rdale:

* With code like the following, the QtRuby runtime was choosing
  an operator method which took a QByteArray and a QString and
  returned a QString. So the 'block' became a Ruby String, rather
  than staying as a Qt::ByteArray:

        block = Qt::ByteArray.new
    
        if comment
            block += "/*\n"
            block += "    " + header + "\n"

  So the operator '+' for Qt::ByteArray is special cased to return
  a Qt::ByteArray.
* The example dialogs/simplewizard now works correctly

CCMAIL: kde-bindings at kde.org


 M  +17 -0     ChangeLog  
 M  +3 -2      rubylib/examples/dialogs/simplewizard/classwizard.rb  
 M  +14 -0     rubylib/qtruby/Qt.cpp  


--- trunk/KDE/kdebindings/qtruby/ChangeLog #544017:544018
@@ -1,3 +1,20 @@
+2006-05-23  Richard Dale  <rdale at foton.es>
+
+	* With code like the following, the QtRuby runtime was choosing
+	  an operator method which took a QByteArray and a QString and
+	  returned a QString. So the 'block' became a Ruby String, rather
+	  than staying as a Qt::ByteArray:
+
+        block = Qt::ByteArray.new
+    
+        if comment
+            block += "/*\n"
+            block += "    " + header + "\n"
+
+	  So the operator '+' for Qt::ByteArray is special cased to return
+	  a Qt::ByteArray.
+	* The example dialogs/simplewizard now works correctly
+
 2006-05-22  Richard Dale  <rdale at foton.es>
 
 	* Fix regression for dynamic class creation via QMetaObject info causing
--- trunk/KDE/kdebindings/qtruby/rubylib/examples/dialogs/simplewizard/classwizard.rb #544017:544018
@@ -68,7 +68,7 @@
         header = @thirdPage.headerLineEdit.text
         implementation = @thirdPage.implementationLineEdit.text
     
-        block = ""
+        block = Qt::ByteArray.new
     
         if comment
             block += "/*\n"
@@ -128,9 +128,10 @@
                                     [   headerFile.fileName(), headerFile.errorString()] ) )
             return
         end
+
         headerFile.write(block)
     
-        block = ""
+        block = Qt::ByteArray.new
     
         if comment
             block += "/*\n"
--- trunk/KDE/kdebindings/qtruby/rubylib/qtruby/Qt.cpp #544017:544018
@@ -1101,6 +1101,18 @@
 	rb_raise(rb_eArgError, "Invalid argument list");
 }
 
+// There is a QByteArray operator method in the Smoke lib that takes a QString
+// arg and returns a QString. This is normally the desired behaviour, so
+// special case a '+' method here.
+static VALUE
+qbytearray_append(VALUE self, VALUE str)
+{
+    smokeruby_object *o = value_obj_info(self);
+	QByteArray * bytes = (QByteArray *) o->ptr;
+	(*bytes) += (const char *) StringValuePtr(str);
+	return self;
+}
+
 // The QtRuby runtime's overloaded method resolution mechanism can't currently
 // distinguish between Ruby Arrays containing different sort of instances.
 // Unfortunately Qt::Painter.drawLines() and Qt::Painter.drawRects() methods can
@@ -2672,6 +2684,8 @@
 		qtextlayout_class = klass;
 	} else if (packageName == "Qt::Variant") {
 		qvariant_class = klass;
+	} else if (packageName == "Qt::ByteArray") {
+		rb_define_method(klass, "+", (VALUE (*) (...)) qbytearray_append, 1);
 	} else if (packageName == "Qt::Char") {
 		rb_define_method(klass, "to_s", (VALUE (*) (...)) qchar_to_s, 0);
 	} else if (packageName == "Qt::ItemSelection") {



More information about the Kde-bindings mailing list