从C应用程序中使用Qt库 [英] Use a Qt library from a C application
问题描述
有没有办法写一个Qt库,这样我就可以使用它(静态链接被罚款)在C应用程序?
我的C code是巨大的,旧的,不会转换为C ++没有工作的过多的。我这样说是因为其他类似的问题似乎回答只是让你的C code Qt的应用程序。这是不是一种选择。
我希望我可以写一个Qt库,并在某种程度上,让它从C(东西QLibrary文档中提到的)呼吁建立它。
Is there a way to write a qt library such that I can then use it (statically linked is fine) in a C application? My C code is huge, old and will not convert to C++ without an inordinate amount of work. I say this as other similar questions seem to answer "just make your C code a Qt app". That's not an option. I hope I can write a qt library, and build it in a way that lets it be called from C (something alluded to in QLibrary documentation).
符号必须导出为一个C
从库函数
解析()工作。这意味着该
功能必须被包裹在一个外部
C块,如果库是编译
用C ++编译器。在Windows中,这
还需要使用DLLEXPORT的
宏;看到细节解析()
这是如何实现的。
The symbol must be exported as a C function from the library for resolve() to work. This means that the function must be wrapped in an extern "C" block if the library is compiled with a C++ compiler. On Windows, this also requires the use of a dllexport macro; see resolve() for the details of how this is done.
有人能确认/否认,我能做到这一点,让我知道我有多么QT可以把在图书馆?
我不需要一个GUI,但想用一些SQL处理。
Can someone confirm/deny that I can do this, and let me know how much "qt" I can put in the library? I don't need a GUI but would like to use some of the SQL handling.
干杯
迈克
推荐答案
您可以把尽可能多的Qt在如你所愿,包括完整的UI功能的库。问题的症结,既然你想从C code访问它,您必须提供自己的接入功能和你的C功能将被限制为您提供力所能及的访问级别。
You can put as much Qt in a library as you wish, including full UI capability. The rub is that since you want to access it from C code, you must provide your own access functions and your C functionality will be constrained to whatever level of access you provide.
您甚至可以通过C和C之间的Qt对象指针++,但你需要扔东西,C能编译 - 无论是无效*
或preferably您自己的新类型定义(如 C_QString *
)。至C code这些指针将是不透明的,但他们仍然是有效的。
You can even pass Qt object pointers between C and C++ but you'll need to cast them into something that C can compile -- either void *
or preferably your own new type definition (such as C_QString *
). To C code these pointers will be opaque, but they'll still be valid.
这篇关于从C应用程序中使用Qt库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!