Does Qt have a C interface?

后端 未结 7 720
孤街浪徒
孤街浪徒 2020-12-04 19:03

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 hav

相关标签:
7条回答
  • 2020-12-04 19:19

    Qt uses the Meta Object Compiler (MOC) to make the signal and slot magic work (e.g. make function callbacks based on user signal and slot definitions). So Qt isn’t actuall C++, but is really Qt’s own syntax, which is a lot like C++, but with signals and slots. This makes ‘external “c”’ useless.

    0 讨论(0)
  • 2020-12-04 19:28

    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.

    0 讨论(0)
  • 2020-12-04 19:28

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

    0 讨论(0)
  • 2020-12-04 19:32

    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.

    0 讨论(0)
  • 2020-12-04 19:36

    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!

    0 讨论(0)
  • 2020-12-04 19:39

    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.

    0 讨论(0)
提交回复
热议问题