[Kde-bindings] Containers passed by reference

Richard Dale rdale at foton.es
Fri Dec 12 12:56:42 UTC 2008


On Friday 12 December 2008 12:23:12 David Palacio wrote:
> This is similar to the QImage::bits one. In the Okular bindings a QVector
> is marshalled to a Ruby array but the original QVector is never updated.
> This is not the expected behaviour by Okular.
>
> virtual bool   loadDocument (const QString &fileName, QVector< Page * >
> &pagesVector)=0
> is the c++ signature of a method that needs to be implemented in a
> generator. pagesVector is a QVector& that will be updated inside this
> method.
>
> I have confirmed, on the C++ side, that the pagesVector has zero size.
>
> This would need a special case: create a Ruby Array outside the method and
> pass it as an argument. When the method finishes, update the QVector.
That should work. In okularhandlers.cpp the QList marshaller is defined like 
this:

DEF_LIST_MARSHALLER( OkularPageList, QVector<Okular::Page*>, Okular::Page )

The macro is defined in qtruby/src/marshall_macros.h, and on line 80 there is 
this code to copy the C++ version of the list to the Ruby one after a method 
has been called:

			m->item().s_voidp = cpplist;
			m->next();

			if (!m->type().isConst()) {
				rb_ary_clear(list);
	
				for(int i = 0; i < cpplist->size(); ++i ) {
					VALUE obj = getPointerObject( (void *) cpplist->at(i) );
					rb_ary_push(list, obj);
				}
			}

Not that the code after the 'm->next()' call is run after the C++ method has 
has been called.

So I'm not sure why it isn't working in your example.

-- Richard



More information about the Kde-bindings mailing list