我应该学习 GTK+ 还是GTKMM?

发布于 2024-07-14 15:25:23 字数 158 浏览 9 评论 0原文

我是一名 C# 程序员,大约 2 年前开始使用 ubuntu。 我想学习 C 或 C++ 的 GUI 编程。 我不太喜欢单声道,它往往会在我的系统上崩溃。 我对 C++ 有基本的了解。 我从来没有用过C语言,但是它看起来很酷。 我应该学习/使用哪个工具包? 给出每个的优点/缺点。 谢谢!

I am a C# programmer who started using ubuntu about 2 years ago. I'm wanting to learn GUI programming in either C or C++. I don't really like mono, it tends to crash on my system. I have a basic understanding of C++. I have never worked in C, but it looks cool. Which toolkit should I learn/use? Give Pro/Cons of each. Thanks!

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

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

发布评论

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

评论(7

转角预定愛 2024-07-21 15:25:23

我可能会被指责有偏见,因为我确实为 gtkmm 做出了贡献,但我首先是一个用户,所以......无论如何,如果您熟悉 C++,我会强烈推荐 gtkmm。 gtkmm 的内存管理比 GTK+ 更容易,因为引用计数对象是通过智能指针自动管理的。 您还可以将对象实例化为自动变量(例如在堆栈上),并让它们的生命周期由它们的作用域决定。 因此在实践中,使用 gtkmm 比使用 GTK+ 更容易避免内存泄漏。

gtkmm 相对于 GTK+ 的另一个巨大优势(在我看来)是使用类型安全信号框架。 在 GTK+ 中,您经常需要将内容作为 void 指针传递,然后将它们转换为您认为应该的类型。 在 gtkmm 中,您不需要这样做,并且可以利用编译器在信号处理程序上强制执行类型安全。

相对于 C/GTK+ 的另一大优势是易于派生新类。 在 GTK+ 中,您需要编写大量样板代码,并且基本上重新实现您在 C++ 中作为语言一部分免费获得的东西(例如继承、构造函数、析构函数等)。 这更加乏味且容易出错。

greyfade 提到 gtkmm 并不完整,在某种程度上他是对的——gtkmm 并没有涵盖 GTK+ API 中的所有内容(尽管它非常接近)。 但实际上这不是问题,因为您始终可以直接从 gtkmm 代码使用 C/GTK+ API。 这种 C 兼容性是 C++ 相对于 C# 或 python 绑定之类的巨大优势,如果绑定不覆盖部分 API,您将别无选择。

选择 GTK+ 而不是 gtkmm (IMO) 的唯一真正原因是 gtkmm 有一点额外的开销,因为它是 C 库顶部的包装器(但这通常只是一个函数调用,影响可以忽略不计) ,或者如果您讨厌或不能使用 C++。

I could be accused of bias since I do help contribute to gtkmm, but I was a user first, so... In any case, I would highly recommend gtkmm if you're comfortable with C++. Memory management is much easier with gtkmm than with GTK+ because reference-counted objects are managed automatically with smart pointers. You can also instantiate objects as auto variables (e.g. on the stack) and have their lifetime determined by their scope. So in practice, it's much easier to avoid memory leaks with gtkmm than with GTK+.

Another huge advantage of gtkmm over GTK+ (in my opinion) is the use of a type-safe signals framework. In GTK+, you constantly need to pass things as void pointers and then cast them around to the type you think they should be. In gtkmm, you dont need to do this, and can take advantage of the compiler enforcing type-safety on your signal handlers.

Another big advantage over C/GTK+ is the ease of deriving new classes. In GTK+, you need to write a lot of boilerplate code and basically re-implement things that you get for free in C++ as part of the language (e.g. inheritance, constructors, destructors, etc). This is more tedious and error-prone.

greyfade mentioned that gtkmm is incomplete, and he's right to a certain extent -- gtkmm does not cover absolutely everything in the GTK+ API (though it gets awfully close). But in practice this is not a problem because you can always use the C/GTK+ API directly from your gtkmm code. This C compatibility is a huge advantage of C++ over something like C# or python bindings where you would have no alternatives if the binding didn't cover part of the API.

The only real reasons to choose GTK+ over gtkmm (IMO) are that gtkmm has a little additional overhead since it is a wrapper on top of the C library (but this is generally just a single function call, which is going to have negligible impact), or if you hate or can't use C++.

南风几经秋 2024-07-21 15:25:23

如果您是 C# 程序员,为什么不看看 Vala 呢?

我的大多数 Linux GUI 应用程序都使用 pygtk,但 Python 对于我现在正在进行的项目来说太慢了,所以我尝试选择 GTK+ 和 GTKmm 之一。 然后我遇到了瓦拉。

这是一种相当新的语言,因此目前文档非常有限,但我认为它兼具了两全其美的优点:C# 语法和 C 速度。

If you're a C# programmer, why don't you take a look at Vala?

I use pygtk for most of my Linux GUI applications, but Python was simply too slow for the project I'm working on right now, so I was trying to pick one of GTK+ and GTKmm. Then I met Vala.

It's a pretty new language, and therefore documentation is pretty limited at the moment, but I think it has the best of both worlds: C# syntax with C speed.

心奴独伤 2024-07-21 15:25:23

由于您更熟悉 C++,您可能会发现 GTKmm 更适合,因为您可以使用 RAII 等惯用语。 不幸的是,GTKmm 有点不完整,缺少 GTK 中一些较少使用的部分。

然而,GTK+ 本身本质上公开了一个类似于 C++ 中的对象模型,但仅包含 C 函数。 C++ 中的构造和销毁之类的事情是在 C API 中显式完成的,并且小部件的实例仅通过指针进行处理。

尝试两者,看看哪一个更适合您的项目。

Since C++ is more familiar to you, you may find GTKmm to be a better fit, since you can use idioms like RAII. Unfortunately, GTKmm is a little incomplete and is missing a few of the lesser-used parts of GTK.

GTK+ on its own, however, essentially exposes an object model similar to what you find in C++, but with only C functions. Things like construction and destruction in C++ are done explicitly in the C API and instances of widgets are handled via pointers exclusively.

Try both and see which fits your project better.

不可一世的女人 2024-07-21 15:25:23

正如许多人所说,Gtkmm 确实为您提供了良好的内存管理、引用计数对象等。不过,它确实在一个方面有所下降。 文档。 整个 Gtkmm 项目都遭受“无文档”现象的困扰,其中发布的(以及在第 3 方站点上重新发布的)文档只是头文件的 javadoc 扫描。

只是想让你知道你会遇到什么。 例如, 滚动窗口 是 Gtkmm 中记录较好的类之一。

Like many have said, Gtkmm does provide you with good memory management, reference counted objects, etc. It does fall down in one department, though. Documentation. The whole of the Gtkmm project suffers from the "undocumentation" phenomena, where the posted (and reposted on 3rd party sites) documentation is simply a javadoc scan of the header files.

Just wanted you to know what you'd be getting into. For instance, the Scrolled Window is one of the better documented classes in Gtkmm.

意中人 2024-07-21 15:25:23

你看过Qt吗?
这是很好的 C++ 设计、跨平台和 LGPL

Have you looked at Qt?
It's nice C++ design, cross platform and LGPL

忘羡 2024-07-21 15:25:23

我认为最好的方法是先学习 gtkmm! 完成 gtkmm 的基础知识后,学习 GTK+ 应该相当简单(前提是您了解 C 并且熟悉指针)。

如果你不懂 C,你可以通过阅读 Dennis Ritchie 的《C 编程语言》来快速学习它。

我建议你先学习 gtkmm,因为它是专门为 C++ 设计的,C++ 与 C# 有点相似,因为两者都是面向对象的,所以gtkmm会比GTK+更容易先学。

gtkmm之后,你可以转向GTK+

大多数开源公司都使用GTK+而不是gtkmm,所以GTK+是值得学习的!

I think the best way to go would be first learn gtkmm! After you are done with the basics of gtkmm, GTK+ should be fairly straightforward to learn(provided you know C and are comfortable with pointers).

In case you don't know C, you can learn it quickly by reading The C Programming Language by Dennis Ritchie

I recommend you to learn gtkmm first because it is specially designed for C++, which is somewhat similar to C# since both are Object Oriented, so gtkmm will be relatively easy to learn first than GTK+.

After gtkmm, you can move on to GTK+

Most of the open source companies use GTK+ rather than gtkmm, so GTK+ is worthwile to learn!

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