[Kde-bindings] Crash in qtruby4 (svn) using custom C++ classes

Richard Dale rdale at foton.es
Thu Jun 19 12:35:50 UTC 2008


On Thursday 19 June 2008 10:47:54 Stefano Crocco wrote:
> I'm attempting to use the latest svn revision of korundum4 to build an
> application which uses a custom C++ class, following the procedure
> explained in a thread on the korundum forum
> (http://rubyforge.org/forum/forum.php?thread_id=10371&forum_id=723). The
> code I wrote worked correctly with an older revision (from about a month
> ago), but now it crashes when I try to write a C++ slot which returns a
> string.
>
> Here's a sample code which causes the crash:
>
> #include <ruby.h>
> #include <QApplication>
> #include <QList>
> #include <QPoint>
> #include <QWidget>
>
> class MyWidget: public QWidget{
>   Q_OBJECT
>
>   public:
>   MyWidget(QWidget*parent = 0):QWidget(parent){
>   }
>   ~MyWidget(){}
>
>   public slots:
>   QString string_test(){return QString("My test");}
>   int int_test(){return 124;}
>   QPoint point_test(){return QPoint(12,89);}
> };
>
> #include "ext_moc.cpp"
>
> static VALUE create_my_widget(VALUE self, VALUE name){
>   QWidgetList l = QApplication::allWidgets();
>   QWidget * parent = l.first();
>   MyWidget * w = new MyWidget(parent);
>   QString objName = STR2CSTR(name);
>   w->setObjectName(objName);
>   return Qnil;
> }
>
> extern "C" void Init_ext(void){
>   typedef VALUE ( *HOOK ) ( ... );
>   rb_define_method(rb_cObject, "create_my_widget",
> reinterpret_cast<HOOK>(create_my_widget), 1); }
>
> Once compiled that as a ruby extension file called ext.so, if I run the
> following ruby code:
>
> require 'Qt4'
> require 'ext'
>
> app = Qt::Application.new []
> w = Qt::Widget.new
> create_my_widget "test"
> my_widget = w.findChild Qt::Object, "test"
> puts "int_test:#{my_widget.int_test}"
> puts "point_test: #{my_widget.point_test.inspect}"
> puts "doing string_test"
> p my_widget.string_test
>
> This is what I get:
> int_test:124
> point_test: nil
> doing string_test
> try.rb:11: [BUG] Segmentation fault
> ruby 1.8.6 (2008-03-03) [i686-linux]
>
> And here's the backtrace obtained by running ruby in gdb:
> #0  0xb7afc222 in QString::operator= () from /usr/lib/qt4/libQtCore.so.4
> #1  0xb6b3af73 in MyWidget::qt_metacall () from ./ext.so
> #2  0xb756356e in InvokeNativeSlot::invokeSlot (this=0xbfe447f4) at
> /home/stefano/Desktop/kdebindings/ruby/qtruby/src/Qt.cpp:413 #3  0xb756366d
> in InvokeNativeSlot::mainfunction (this=0xbfe447f4) at
> /home/stefano/Desktop/kdebindings/ruby/qtruby/src/Qt.cpp:424 #4  0xb759c96c
> in SigSlotBase::next (this=0xbfe447f4) at
> /home/stefano/Desktop/kdebindings/ruby/qtruby/src/marshall_types.cpp:628 #5
>  0xb7568d19 in method_missing (argc=1, argv=0xbfe44bc0, self=3060248180) at
> /home/stefano/Desktop/kdebindings/ruby/qtruby/src/Qt.cpp:856 #6  0xb7f08805
> in call_cfunc () from /usr/lib/libruby18.so.1.8
> #7  0xb7f12945 in rb_call0 () from /usr/lib/libruby18.so.1.8
> #8  0xb7f12ad1 in rb_call () from /usr/lib/libruby18.so.1.8
> #9  0xb7f133ad in rb_funcall2 () from /usr/lib/libruby18.so.1.8
> #10 0xb7f18b36 in method_missing () from /usr/lib/libruby18.so.1.8
> #11 0xb7f12bc3 in rb_call () from /usr/lib/libruby18.so.1.8
> #12 0xb7f0d599 in rb_eval () from /usr/lib/libruby18.so.1.8
> #13 0xb7f0fcc5 in rb_eval () from /usr/lib/libruby18.so.1.8
> #14 0xb7f1dfe3 in ruby_exec_internal () from /usr/lib/libruby18.so.1.8
> #15 0xb7f1e023 in ruby_exec () from /usr/lib/libruby18.so.1.8
> #16 0xb7f1e058 in ruby_run () from /usr/lib/libruby18.so.1.8
> #17 0x08048715 in main ()
I've just tried it, and it works for me:

mardigras rdale 961% ruby try.rb
int_test:124
point_test: nil
doing string_test
"My test"

But point_test() shouldn't be returning nil, and so there is some sort of bug 
with that. I'll see if I can find what is causing that, as it used to be 
possible to return things like QPoints.

I'm not sure why you're getting a crash and I'm not.

-- Richard



More information about the Kde-bindings mailing list