PDA

View Full Version : How to Integrate Qt with 'C'



deepakn
8th August 2007, 08:54
Hello folks,
I will be much grateful if anybody can give me a simple example where some code written in C [some simple application, like a hello world ] is executed through Qt [ie., through a Qt UI ].

Any pointers in Trolltech docs? or some previous threads here? I tried searching here, but found none so far.

Any kind of guidance will be much appreciated.
Thanks:)
Deepak

PS: I am using Qt 4.2.2 on WinXp

marcel
8th August 2007, 10:16
I don't know...
I think there was a C bindings for Qt package, but for version 3.x.
I don't remember the link anyway.

What about making a C++ Qt library( shared or static) and link your C program against it?
In the library you will have the functionality implemented in C++( classes, etc...), but you will export only some C style functions, which are wrappers for those classes.

Or, switch to C++ :).

Regards

Gopala Krishna
8th August 2007, 13:04
Well , qt and kde bindings for language such as python, ruby , c# etc are all(or most of them) based on smoke qt library which is completely c based (ofcourse qt4). I couldn't find exact link on google but may be if you install qtruby or qtc# you will get the libraries. You might even contact the respective authors. :)

jacek
8th August 2007, 15:46
I will be much grateful if anybody can give me a simple example where some code written in C [some simple application, like a hello world ] is executed through Qt [ie., through a Qt UI ].
Do you want to execute a C appplication from within Qt application or simply call some C functions from Qt code?

You can do the latter without any problems, since C++ is compatible with C. All you need is to wrap C headers in extern "C" block. For the former use QProcess.