[Kde-bindings] How to unserialize types defined in other Qt apps in QtRuby?

Yaohan Chen yaohan.chen at gmail.com
Thu Feb 23 07:00:14 UTC 2012


I compiled several of Quassel's C++ files which define 
the custom types
(most files under "src/common" at 
<http://git.quassel-
irc.org/?p=quassel.git;a=tree;f=src/common;hb=HEAD>),
into an extension, and loaded it in my QtRuby client, 
and unserialization
still doesn't work for the types. I didn't think this 
would be enough,
but I'm not sure what else I need to do now, or if I'm 
going in the right
direction. These C++ files, for example BufferInfo.
{h,cpp}, do define
operator>> and operator<<(QDataStream, type), and use 
Q_DECLARE_METATYPE
and qRegisterMetaType with them.

Paolo's link as well as Richard Dale's 
<https://blogs.kde.org/node/2679>
talk about the ability to call a C++ QObject's slots 
in QtRuby, but I'm
not sure how to adapt the technique in my application. 
I don't have
the objects of Quassel types yet, because they're 
serialized in the
stream. If I arbitrarily instantiate one in the 
extension, it doesn't
seem helpful in unserializing other instances. And is 
it possible to
use operator>> as a slot?


Yaohan Chen

On Wednesday, February 22, 2012 04:50:50 PM Arno Rehn 
wrote:
> On Tuesday 21 February 2012 22:35:42 Yaohan Chen 
wrote:
> > Hello,
> > 
> > How can I unserialize objects of types defined in 
a C++ Qt app, through a
> > Qt::DataStream in QtRuby?
> > 
> > I am trying to create a scripting interface for 
the Qt IRC client Quassel
> > <http://quasselirc.org>. Quassel'score connects to 
IRC networks, and its
> > client
> > displays its user interface. The two communicate 
through a socket, sending
> > QVariant maps and lists to each other, and each 
map or list is prefixed
> > with a uint32 indicating its size in the socket. 
My QtRuby client is able
> > to read some of the messages sent by core, but not 
the ones containing
> > types defined by Quassel. These messages show up 
as empty Qt maps. My
> > code is at <https://github.com/hagabaka/Quassel-
Ruby> if it's of any
> > interest.
> > 
> > It seems that normally qRegisterMetaType would be 
used for this, but I'm
> > not sure how to call a template function QtRuby. I 
don't have much
> > experience with C++ Qt programming either, but I 
would appreciate any
> > pointers.
> If the types in question are custom Quassel types, 
you're pretty much out of
> luck, I'm afraid.
> Quassel then uses custom operator<< and operator>> 
for serializing these
> types which the QtRuby runtime can't know about.
> You could create a wrapper C++ library for those 
operators only and then
> call them from Ruby - Paolo has written a nice blog 
entry about easy C++
> interop:
> 
http://pcapriotti.wordpress.com/2010/12/06/effective-
qt-in-ruby-part-3-2/
> 
> I can't think of any other quick solution now.



More information about the Kde-bindings mailing list