如何创建可以从 C 调用的基于 Qt 的库
我正在尝试构建一个简单的库,它使用 Qt 的一些功能(没有事件循环,只是一些图像操作和文件加载),然后从标准 C 程序调用该库。我已在此处查看了答案,但答案没有为我提供足够的信息来解决问题。我已将该库构建为要链接的静态库,并使用 extern "C"
包装了函数调用,但我收到了一堆错误,从 /usr/include/QtCore 开始/qnamespace.h:-1: 在函数 'QT_MODULE':/usr/include/QtCore/qnamespace.h:54: 错误: 未知类型名称 'namespace'.
有没有人有关于链接到的简短教程来自 C
程序的 Qt 库?仅供参考,一切都在 Linux (Fedora 15) 下进行,并且 C
程序和 Qt 库都是使用 QtCreator
构建的。
I'm trying to build a simple library that uses some of Qt's functionality (no event loop, just some image manipulation and file loading) and then call that library from a standard C
program. I've reviewed the answer here, but the answer did not provide enough information for me to resolve the problem. I have built the library as a static library to be linked, and wrapped the function calls with extern "C"
, but I get a bunch of errors, starting with /usr/include/QtCore/qnamespace.h:-1: In function ‘QT_MODULE’:/usr/include/QtCore/qnamespace.h:54: error: unknown type name ‘namespace’.
Does anyone have a short tutorial on linking to Qt libraries from a C
program? FYI, everything is under Linux (Fedora 15), and both the C
program and the Qt library are being built with QtCreator
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您想制作一个用于创建和删除 QImage 的包装器,可以这样做:
在您的头文件中:
在您的源文件中:
my_qimage_t
类型从调用者的角度来看,它是一个黑匣子。所有操作都必须通过您的库通过传递这个不透明的指针来完成。Lets say you want to make a wrapper for creating and deleting
QImage
, it could be done something like this:In your header file:
And in your source file:
The
my_qimage_t
type is, from the callers perspective, a black box. All manipulation has to be done through your library, by passing this opaque pointer around.