简体   繁体   English

Qt有C接口吗?

[英]Does Qt have a C interface?

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. 我也无法在官方Qt文档中找到任何细节。 So does Qt have C bindings or not? Qt也有C绑定吗?

Short answer: no. 简答:不。

If you need a comprehensive GUI toolkit for C, you can use GTK+. 如果您需要一个全面的GUI工具包,您可以使用GTK +。

To use Qt, you must have a C++ compiler. 要使用Qt,您必须拥有C ++编译器。 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). 但这并不意味着你的“应用程序逻辑”不能用C语言编写,用C编译器编译并仔细链接到C ++部分(带有Qt的GUI)。 This application logic can be generic, linkable into other executables (pure-C, mixed C/C++, etc.) It all depends on what you need. 这个应用程序逻辑可以是通用的,可链接到其他可执行文件(纯C,混合C / C ++等)。这完全取决于你需要什么。

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. 但是,对于C ++来说,Qt非常棒,而且即使你仍然希望在C语言中保留部分内容,这也是决定在特定项目中使用C ++的一个很好的理由。

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. 不幸的是,但是你可以将你的程序塑造成一套库来实现你的业务逻辑并用C语言编写它们,然后你可以使用一点点C ++将你用库写的内容与使用QT的GUI绑定。

This is a good approach also because later you can reuse your library and implement many other front-ends with different toolkits or languages! 这是一个很好的方法,因为以后您可以重用您的库并使用不同的工具包或语言实现许多其他前端!

No. Qt is C++. 不,Qt是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. 但是你可以在任何地方编写C风格的代码,它们不会交互/创建GUI元素,并使用您选择的C ++编译器编译整个事物。

There used to be a Binding called QtC, but searching for it reveals this thread : 曾经有一个名为QtC的Binding,但搜索它会显示这个帖子

From Richard Dale: 来自Richard Dale:

I used to maintain C bindings that were used by Objective-C and Qt# bindings. 我曾经维护过Objective-C和Qt#绑定使用的C绑定。 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库要好得多,虽然它不是C绑定,但我废弃了QtC绑定而不是使用smoke。

Smoke is here . 烟在这里 I have been unable find a clear reference the QtC Bindings anywhere, though I remember hearing about them. 我无法在任何地方找到QtC Bindings的明确参考,但我记得听说过它们。

I don't think it does. 我不这么认为。 Qt is always described as a "class library" and it requires C++ compilers to build. Qt总是被描述为“类库”,它需要构建C ++编译器。 You could try to write/find a DLL/interface that will be wrap around QT and provide an API to a C layer. 您可以尝试编写/查找将包装QT的DLL /接口,并为C层提供API。

您总是可以使用C ++编译器,只需将C ++转换为C,然后调用它生成的错位名称等。:-)

Qt uses the Meta Object Compiler (MOC) to make the signal and slot magic work (eg make function callbacks based on user signal and slot definitions). Qt使用元对象编译器(MOC)使信号和插槽魔术工作(例如,根据用户信号和插槽定义进行函数回调)。 So Qt isn't actuall C++, but is really Qt's own syntax, which is a lot like C++, but with signals and slots. 所以Qt不是真正的C ++,但它实际上是Qt自己的语法,它很像C ++,但有信号和插槽。 This makes 'external “c”' useless. 这使得“外部”c“'无用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM