# Qtruby - calling a C application

**URL:** <https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842>\
**Category:** Ruby\
**Created:** [January 15, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842 "2007-01-15T18:11:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@Fredrik\_J](https://www.ruby-forum.com/u/Fredrik_J)\
**Post date:** [January 15, 2007, 6:11pm UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842/1 "2007-01-15T18:11:18Z")

</div>

Hello all!  
Here is a question for all you Qtruby experts:

I am writing a GUI with Qtruby, which is working great. I am also using  
some software written in C (RTP, [http://web.cecs.pdx.edu/~watt/rtp/](http://web.cecs.pdx.edu/~watt/rtp/))  
that is plotting data in Qt. Now - I would like to tell this C  
application to use the main window that I have created in my Ruby code  
instead of creating its own main window. But how on earth do I pass  
this reference to my application written in C? I am guessing it is just  
some index number telling which window it is (?)

Thanks for any help!  
Best regards,  
Fredrik

---

<div class="post-metadata">

**Author:** ![Fredrik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@Fredrik\_J](https://www.ruby-forum.com/u/Fredrik_J)\
**Post date:** [January 15, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842/2 "2007-01-15T19:21:27Z")

</div>

Fredrik J wrote:

> Hello all!  
> Here is a question for all you Qtruby experts:
> 
> I am writing a GUI with Qtruby, which is working great. I am also using  
> some software written in C (RTP, [http://web.cecs.pdx.edu/~watt/rtp/](http://web.cecs.pdx.edu/~watt/rtp/))  
> that is plotting data in Qt. Now - I would like to tell this C  
> application to use the main window that I have created in my Ruby code  
> instead of creating its own main window. But how on earth do I pass  
> this reference to my application written in C? I am guessing it is just  
> some index number telling which window it is (?)  
> I’ve just downloaded the RTP sources, and see that they are very old  
> and written for Qt 2.x.

I don’t think it’s possible to have apps from two different processes  
writing to the same window. And as QtRuby uses either Qt 3.x or Qt 4.x,  
you can’t really integrate the Ruby code with Qt 2.x RTP stuff in the  
same process either. If you could port RTP to Qt 3.x it might be  
possible, but not otherwise.

– Richard

---

<div class="post-metadata">

**Author:** ![Fredrik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@Fredrik\_J](https://www.ruby-forum.com/u/Fredrik_J)\
**Post date:** [January 15, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842/3 "2007-01-15T20:14:42Z")

</div>

Fredrik J wrote:

> Hello all!  
> Here is a question for all you Qtruby experts:
> 
> I am writing a GUI with Qtruby, which is working great. I am also using  
> some software written in C (RTP, [http://web.cecs.pdx.edu/~watt/rtp/](http://web.cecs.pdx.edu/~watt/rtp/))  
> that is plotting data in Qt. Now - I would like to tell this C  
> application to use the main window that I have created in my Ruby code  
> instead of creating its own main window. But how on earth do I pass  
> this reference to my application written in C? I am guessing it is just  
> some index number telling which window it is (?)

If I understand you right, you’re running an external application and  
you would like your qtruby application to ‘swallow’ it ? (I use swallow,  
like in FvwmButton which is doing something of the like).

Look at the QX11Embed documentation, you should find what you need.  
(it seems to me it’s only Qt4, but I can’t say for sure).

Cheers,

Vincent

---

<div class="post-metadata">

**Author:** ![Fredrik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@Fredrik\_J](https://www.ruby-forum.com/u/Fredrik_J)\
**Post date:** [January 16, 2007, 11:25am UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842/4 "2007-01-16T11:25:47Z")

</div>

Vincent F. wrote:

> > some index number telling which window it is (?)
> 
> If I understand you right, you’re running an external application and  
> you would like your qtruby application to ‘swallow’ it ? (I use swallow,  
> like in FvwmButton which is doing something of the like).
> 
> Look at the QX11Embed documentation, you should find what you need.  
> (it seems to me it’s only Qt4, but I can’t say for sure).  
> Yes, you’re right it is in Qt4, and it does sound possible to do what  
> Fredrik wants with the QX11Embed classes.

Those classes aren’t included in the generation of the Smoke library  
that the current release of Qt4 QtRuby uses. I’ve now added the header  
QtGui/qx11embed\_x11.h to the smoke/qt/header\_list file so the  
QX11EmbedContainer and QX11EmbedWidget classes, and so they will be in  
the next release.

---

<div class="post-metadata">

**Author:** ![Fredrik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@Fredrik\_J](https://www.ruby-forum.com/u/Fredrik_J)\
**Post date:** [January 16, 2007, 11:26am UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842/5 "2007-01-16T11:26:49Z")

</div>

Thanks for helping! I think I am in over my head here though, after  
reading your posts I understand that this is not so easily done. I  
think I will leave RTP in its own window. It’s not as pretty as it  
would have been if it was in the same window, but the function is still  
the same.

/Fredrik

---

<div class="post-metadata">

**Author:** ![Fredrik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@Fredrik\_J](https://www.ruby-forum.com/u/Fredrik_J)\
**Post date:** [January 15, 2007, 8:15pm UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842/6 "2007-01-15T20:15:43Z")

</div>

Fredrik J wrote:

> Hello all!  
> Here is a question for all you Qtruby experts:
> 
> I am writing a GUI with Qtruby, which is working great. I am also using  
> some software written in C (RTP, [http://web.cecs.pdx.edu/~watt/rtp/](http://web.cecs.pdx.edu/~watt/rtp/))  
> that is plotting data in Qt. Now - I would like to tell this C  
> application to use the main window that I have created in my Ruby code  
> instead of creating its own main window. But how on earth do I pass  
> this reference to my application written in C? I am guessing it is just  
> some index number telling which window it is (?)

If I understand you right, you’re running an external application and  
you would like your qtruby application to ‘swallow’ it ? (I use swallow,  
like in FvwmButton which is doing something of the like).

Look at the QX11Embed documentation, you should find what you need.  
(it seems to me it’s only Qt4, but I can’t say for sure).

Cheers,

Vince

---

<div class="post-metadata">

**Author:** ![Fredrik\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@Fredrik\_J](https://www.ruby-forum.com/u/Fredrik_J)\
**Post date:** [January 16, 2007, 11:33am UTC](https://www.ruby-forum.com/t/qtruby-calling-a-c-application/81842/7 "2007-01-16T11:33:50Z")

</div>

Fredrik J wrote:

> Thanks for helping! I think I am in over my head here though, after  
> reading your posts I understand that this is not so easily done. I  
> think I will leave RTP in its own window. It’s not as pretty as it  
> would have been if it was in the same window, but the function is still  
> the same.

Well, I’m disappointed ;-). I hope you would try and explain us  
everything !

Vince

PS: maybe one day, I’ll fiddle with it and post about it on my blog.
