tags:

views:

1159

answers:

6

I've found conflicting answers on the web - some say it does, some say it doesn't. I was unable to find any details in the official Qt documentation either. So does Qt have C bindings or not?

A: 

I don't think it does. Qt is always described as a "class library" and it requires C++ compilers to build. You could try to write/find a DLL/interface that will be wrap around QT and provide an API to a C layer.

Traveling Tech Guy
+11  A: 

No. Qt is C++. But you could just write C-style code everywhere that doesn't interact/create GUI elements and compile the whole thing with your C++ compiler of choice.

Cory Petosky
+17  A: 

Short answer: no.

If you need a comprehensive GUI toolkit for C, you can use GTK+.

To use Qt, you must have a C++ compiler. But it doesn't mean that your "application logic" can't be written in C, compiled with a C compiler and carefully linked to the C++ part (the GUI with Qt). This application logic can be generic, linkable into other executables (pure-C, mixed C/C++, etc.) It all depends on what you need.

Qt is great for C++, though, and it's a good reason to decide using C++ for a particular project, even if you still want to keep parts in C.

Eli Bendersky
+2  A: 

There used to be a Binding called QtC, but searching for it reveals this thread:

From Richard Dale:

I used to maintain C bindings that were used by Objective-C and Qt# bindings. But the Smoke library is much better although it isn't a C binding, and I scrapped the QtC bindings to use smoke instead.

Smoke is here. I have been unable find a clear reference the QtC Bindings anywhere, though I remember hearing about them.

Sean McMillan
A: 

You could always use a C++ compiler that simply translates C++ to C, then call the mangled names it generates, etc. :-)

R..
...bad Idea: when you'll work with a different compiler you may find that name mangling is different. Or is there a starndard for mangling?
Dacav
If you just 'compile' the C++ code (Qt) to C, from then on you can just treat the generated C code as the "source". Unless you go back to regenerate it, the compiler used to generate it is no longer relevant. That said, this answer is not intended to be taken too seriously, but I believe it is a correct answer nonetheless.
R..
+2  A: 

Unfortunately not, but you may shape your program as set of libraries achiving your business logic and write them in C, then you can use a little C++ to bind what you wrote as library with a GUI using QT.

This is a good approach also because later you can reuse your library and implement many other front-ends with different toolkits or languages!

Dacav