C GUI,带有 C++ 骨干?

发布于 2024-07-19 02:42:27 字数 191 浏览 4 评论 0原文

我有一个用 C++ 编写的简单(也很琐碎)的银行应用程序。 我在 ubuntu 上,所以我使用 GNOME (GTK+)。 我想知道是否可以用 C/GTK+ 编写所有 GUI,然后以某种方式将其链接到我的 C++ 代码。 这可能吗?

注意:我不想使用 Qt 或 GTKmm,因此请不要提供这些作为答案。

I have a simple (and also trivial) banking application that I wrote in C++. I'm on ubuntu so I'm using GNOME (GTK+). I was wondering if I could write all my GUI in C/GTK+ and then somehow link it to my C++ code. Is this even possible?

Note: I don't want to use Qt or GTKmm, so please don't offer those as answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

一人独醉 2024-07-26 02:42:27

是的,这是一件非常容易做的事情。 您所要做的就是将一些 C++ 函数公开为“extern C”,以便 UI 代码中的事件处理程序和回调可以调用它们。

如果您无法更改现有的 C++ 源代码 - 没问题。 只需为您的 UI 编写一个 C++ shim,extern 这些函数,然后从那里调用后端函数。

Yes, it's a very easy thing to do. All you have to do is expose some of the C++ functions as "extern C" so that the event handlers and callbacks in your UI code can call them.

In the case that you can't change the existing C++ source - no problem. just write a C++ shim for your UI, extern those functions, and call backend functions from there.

↙温凉少女 2024-07-26 02:42:27

我不明白为什么不,使用适当的 extern "C" 用法,以便您的 C 代码可以调用 C++。 现在,当然,你可能会让自己变得更加困难,但从理论上讲这是合理的。

I don't see why not, with appropriate extern "C" usage so your C code can call into C++. Now, granted, you're probably making it a bit harder on yourself, but it's theoretically sound.

回忆躺在深渊里 2024-07-26 02:42:27

就像其他人建议的那样,您可以为 C++ 库编写一个 C 包装器。 但你也可以用 C++ 编写前端,即使你只使用 C 子集。 如果您不喜欢语言混合,我可以理解,但这是最简单的方法,因为您可以节省编写包装器的时间。

Like others propose you can write a C wrapper for your C++ library. But you can also write the front-end in C++, even if you only use the C subset. I can understand if you don't like the language mixing, but it is the easiest way, because you save the time to write the wrapper.

入怼 2024-07-26 02:42:27

使用 wxWidgets 怎么样?

How about using wxWidgets instead?

始终不够 2024-07-26 02:42:27

您可以将 GTK/C 代码编译为 C++,而不使用 GTKmm,并在本机使用 C++ 代码。

大多数健全的 C 库都可以从本机 C++ 代码中使用,而 GTK+ 本质上是一个 C 库。

You can just compile your GTK/C code as C++ without using GTKmm, and use the C++ code natively.

Most sane C libraries can be used from native C++ code, and GTK+ is fundamentaly a C library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文