我应该学习GTK +还是GTKMM?

时间:2022-09-11 10:27:36

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!

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

7 个解决方案

#1


12  

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.

由于C ++对你来说比较熟悉,你可能会发现GTKmm更合适,因为你可以使用像RAII这样的习语。不幸的是,GTKmm有点不完整,缺少一些较少使用的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.

然而,GTK +本身暴露了一个类似于你在C ++中找到的对象模型,但只有C函数。 C ++中的构造和销毁之类的东西在C API中显式完成,小部件的实例仅通过指针处理。

Try both and see which fits your project better.

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

#2


30  

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+.

我可以被指责偏见,因为我确实帮助了gtkmm,但我是用户第一,所以......无论如何,如果你对C ++感到满意,我强烈推荐gtkmm。使用gtkmm比使用GTK +更容易进行内存管理,因为使用智能指针自动管理引用计数对象。您还可以将对象实例化为自动变量(例如,在堆栈上),并根据其范围确定其生命周期。因此在实践中,使用gtkmm比使用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.

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

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.

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

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.

greyfade提到gtkmm是不完整的,并且他在某种程度上是正确的 - gtkmm并不能完全涵盖GTK + API中的所有内容(尽管它非常接近)。但实际上这不是问题,因为您可以直接从gtkmm代码中使用C / GTK + API。这种C兼容性是C ++相对于C#或python绑定之类的巨大优势,如果绑定没有覆盖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++.

选择GTK +超过gtkmm(IMO)的唯一真正原因是gtkmm有一点额外的开销,因为它是C库顶部的包装器(但这通常只是一个函数调用,这将产生微不足道的影响) ,或者如果你讨厌或不能使用C ++。

#3


16  

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

如果你是C#程序员,为什么不看看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.

我在我的大多数Linux GUI应用程序中使用pygtk,但Python对于我正在进行的项目来说太慢了,所以我试图选择GTK +和GTKmm中的一个。然后我遇到了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.

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

#4


4  

I would suggest to learn vala with gedit.

我建议用gedit学习vala。

http://www.valaide.org/doku.php : vala

http://www.valaide.org/doku.php:vala

https://launchpad.net/valable : Eclipse

https://launchpad.net/valable:Eclipse

http://code.google.com/p/vtg/ : Gedit

http://code.google.com/p/vtg/:Gedit

http://abderrahim.arablug.org/blog/ : anjuta

http://abderrahim.arablug.org/blog/:anjuta

#5


4  

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.

像许多人所说的那样,Gtkmm确实为你提供了良好的内存管理,引用计数对象等等。但它确实在一个部门中存在。文档。整个Gtkmm项目都受到“非文档化”现象的影响,其中发布(并在第三方网站上重新发布)文档只是头文件的javadoc扫描。

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.

只是想让你知道你将要进入什么。例如,滚动窗口是Gtkmm中记录较好的类之一。

#6


2  

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

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

#7


2  

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).

我认为最好的方法是先学习gtkmm!在完成gtkmm的基础知识之后,GTK +应该相当简单易学(前提是你知道C并且对指针感到满意)。

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

如果您不了解C,可以通过阅读Dennis Ritchie的C编程语言快速学习

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+.

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

After gtkmm, you can move on to GTK+

在gtkmm之后,您可以继续使用GTK +

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

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

#1


12  

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.

由于C ++对你来说比较熟悉,你可能会发现GTKmm更合适,因为你可以使用像RAII这样的习语。不幸的是,GTKmm有点不完整,缺少一些较少使用的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.

然而,GTK +本身暴露了一个类似于你在C ++中找到的对象模型,但只有C函数。 C ++中的构造和销毁之类的东西在C API中显式完成,小部件的实例仅通过指针处理。

Try both and see which fits your project better.

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

#2


30  

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+.

我可以被指责偏见,因为我确实帮助了gtkmm,但我是用户第一,所以......无论如何,如果你对C ++感到满意,我强烈推荐gtkmm。使用gtkmm比使用GTK +更容易进行内存管理,因为使用智能指针自动管理引用计数对象。您还可以将对象实例化为自动变量(例如,在堆栈上),并根据其范围确定其生命周期。因此在实践中,使用gtkmm比使用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.

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

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.

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

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.

greyfade提到gtkmm是不完整的,并且他在某种程度上是正确的 - gtkmm并不能完全涵盖GTK + API中的所有内容(尽管它非常接近)。但实际上这不是问题,因为您可以直接从gtkmm代码中使用C / GTK + API。这种C兼容性是C ++相对于C#或python绑定之类的巨大优势,如果绑定没有覆盖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++.

选择GTK +超过gtkmm(IMO)的唯一真正原因是gtkmm有一点额外的开销,因为它是C库顶部的包装器(但这通常只是一个函数调用,这将产生微不足道的影响) ,或者如果你讨厌或不能使用C ++。

#3


16  

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

如果你是C#程序员,为什么不看看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.

我在我的大多数Linux GUI应用程序中使用pygtk,但Python对于我正在进行的项目来说太慢了,所以我试图选择GTK +和GTKmm中的一个。然后我遇到了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.

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

#4


4  

I would suggest to learn vala with gedit.

我建议用gedit学习vala。

http://www.valaide.org/doku.php : vala

http://www.valaide.org/doku.php:vala

https://launchpad.net/valable : Eclipse

https://launchpad.net/valable:Eclipse

http://code.google.com/p/vtg/ : Gedit

http://code.google.com/p/vtg/:Gedit

http://abderrahim.arablug.org/blog/ : anjuta

http://abderrahim.arablug.org/blog/:anjuta

#5


4  

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.

像许多人所说的那样,Gtkmm确实为你提供了良好的内存管理,引用计数对象等等。但它确实在一个部门中存在。文档。整个Gtkmm项目都受到“非文档化”现象的影响,其中发布(并在第三方网站上重新发布)文档只是头文件的javadoc扫描。

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.

只是想让你知道你将要进入什么。例如,滚动窗口是Gtkmm中记录较好的类之一。

#6


2  

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

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

#7


2  

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).

我认为最好的方法是先学习gtkmm!在完成gtkmm的基础知识之后,GTK +应该相当简单易学(前提是你知道C并且对指针感到满意)。

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

如果您不了解C,可以通过阅读Dennis Ritchie的C编程语言快速学习

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+.

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

After gtkmm, you can move on to GTK+

在gtkmm之后,您可以继续使用GTK +

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

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