[Kde-bindings] Qyoto: SIGNALS/SLOTS

Richard Dale Richard_Dale at tipitina.demon.co.uk
Mon Dec 19 12:02:10 UTC 2005

On Saturday 17 December 2005 19:43, Arno Rehn wrote:
> Am Donnerstag, 15. Dezember 2005 14:32 schrieb Arno Rehn:
> > Am Mittwoch, 14. Dezember 2005 20:22 schrieb Adam Treat:
> > > On Wednesday December 14 2005 1:43 pm, you wrote:
> > > > Hi,
> > > >
> > > > I found the following in you code:
> > > > IntPtr s = (this.Instance as QtSharp).RawObject;
> > > >
> > > > does 'RawObject' point to the underlying C++ instance?
> > > > If it does, a second question: How do I get the pointer to the
> > > > C++-instance? It tried it with 'GCHandle.Alloc' but that doesn't seem
> > > > to work.
> > >
> > > Yes, it does.  You can find the code for RawObject and the handling of
> > > C++ pointer interaction in the attached file.
> >
> > Thanks, but here I referr to the smoke-lib. I think we can use the
> > functions of libqtsharp to connect signals to slots. I just wanted to try
> > to use libqtsharp with the smoke-bindings. Therefore I would need to get
> > the pointer to the instance of the object in the smoke-lib.
> OK, here is what I try to do: I want to use libqtsharp to connect a signal
> to a slot. I looked in the files Adam sent and discovered how he connects a
> signal to a C#-delegate. He uses 'RawObject' to get the pointer to the
> C++-instance. I want to connect a signal to a delegate in the same way, but
> I need to get the pointer to the C++-instance created by smoke. I changed
> "_smokeObject" (in Qt.cs) from "private" to "public" to access it outsides
> the class. I then tried to call 'csharp_connect_void' to connect a signal
> to a delegate but that failed. I think '_smokeObject' doesn't point to the
> real C++-instance. I attached my code.
> Maybe Richard can help getting the appropiate IntPtr needed for the
> function-call.
In Qyoto the '_smokeObject' is a pointer directly to the C++ instance, it is a 
struct which contains that pointer, along with several other things. So it is 
the direct equivalent of the Qt# QtSharp class.

From qyoto.h:

struct smokeqyoto_object {
    bool allocated;
    Smoke *smoke;
    int classId;
    void *ptr;

The 'ptr' field is the C++ instance. 'allocated' is true if the C# instance 
was allocated from the C# side, or false if an existing C++ instance was 
wrapped, and the C++ instance shouldn't be deleted on garbage collection. 
'classId' is a numeric identifier that is used in the lookup tables inside 
the Smoke library. 'smoke' is a  handle to the Smoke library instance being 
used for the class (always the same for every class in the current 

The underlying slot/signal implementation and marshalling from QtRuby will 
work fine with Qyoto, and so we don't want to rewrite that without good 
reason. But you might be able to get some ideas about how to combine 
delegates with slots/signals from the Qt# stuff. I learned about the 
'internal' keyword, and 'as' casts anyway, which we can maybe use in Qyoto.

-- Richard

More information about the Kde-bindings mailing list