Linux 我应该选择什么:GTK+ 还是 Qt?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1887070/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 19:35:47  来源:igfitidea点击:

What should I choose: GTK+ or Qt?

linuxqtgtk

提问by Idan

Can someone suggest what's the best uses for those libraries today? Is it just GUI, or do they have database, XML, networking, threading, etc support too?

有人可以建议当今这些库的最佳用途是什么吗?它只是 GUI,还是它们也有数据库、XML、网络、线程等支持?

I was reading about them, and considered starting to learning/using one of them.

我正在阅读它们,并考​​虑开始学习/使用其中之一。

What is the most common one? What's the difference between them? Why would you choose one over the other?

最常见的是什么?它们之间有什么区别?为什么你会选择一个而不是另一个?

采纳答案by Gregory Pakosz

As you seem to primarily target Linux, then the choice mostly depends on the programming language you want to use.

由于您似乎主要针对 Linux,因此选择主要取决于您要使用的编程语言。

If you code in C, then obviously go for GTK+

如果你用 C 编写代码,那么显然选择 GTK+

If you code in C++, go for Qt, otherwise you will need Gtkmm(a C++ wrapper over GTK+)

如果您使用 C++ 编写代码,请选择 Qt,否则您将需要Gtkmm(GTK+ 上的 C++ 包装器)

If you code in Python, both GTK+ and Qt have bindings for the language: see PyGtk, PyQtand PySide(the one launched by Nokia themselves).

如果您使用 Python 编写代码,则 GTK+ 和 Qt 都具有该语言的绑定:请参阅PyGtkPyQtPySide(诺基亚自己推出的那个)。

If you code in Java, Qt is no more a viable option imho as Nokia discontinued Qt Jambi(the Java bindings for Qt).

如果您使用 Java 进行编码,恕我直言,Qt 不再是一个可行的选择,因为诺基亚已停止使用 Qt JambiQt的 Java 绑定)。

Also, Qt is more top-notch regarding its scenegraph QGraphicsSceneAPI, its scripting engine built over Javascript Core (the engine powering WebKit), its state machine and animations framework, and the declarative UI.

此外,Qt 在其场景图QGraphicsSceneAPI、基于 Javascript Core 构建的脚本引擎(支持 WebKit 的引擎)、状态机和动画框架以及声明式 UI方面更为一流。

GTK+ doesn't offer that much although you can use Clutteralongside with it.

尽管您可以将Clutter与它一起使用,但 GTK+ 并没有提供那么多。

If you're specifically looking into DB, XML (GTK+ has a parser for a subset of XML) and threading (GTK+ has GLib) features then Qt will offer all that in QtSql, QtXmland QtConcurrent.

如果您专门研究 DB、XML(GTK+ 具有 XML 子集的解析器)和线程(GTK+ 具有GLib)功能,那么 Qt 将在QtSqlQtXmlQtConcurrent 中提供所有这些。

All in all, I would say Qt is a sure choice. But GTK+ is very capable as well.

总而言之,我会说 Qt 是一个肯定的选择。但是 GTK+ 也非常有能力。

I'm not sure you will get a crystal clear answer for your question, which explains why some people keep preferring Gnome over KDE or vice-versa. Choose what works best for you.

我不确定你的问题会得到一个清晰的答案,这解释了为什么有些人一直更喜欢 Gnome 而不是 KDE,反之亦然。选择最适合您的方式。

PS: I you plan to also target Symbian, then go for Qt.

PS:我你也计划以 Symbian 为目标,然后选择 Qt。

EDIT: Something that is also great with Qt is QtWebView: it brings Chromium into your Qt application to display web content. Others are embedding web content into their application using for instance Awesomium or Berkelium.

编辑:Qt 的另一个优点是QtWebView:它将 Chromium 带入您的 Qt 应用程序以显示 Web 内容。其他人则使用 Awesomium 或 Berkelium 等将 Web 内容嵌入到他们的应用程序中。

回答by ChristopheD

Qt for one sure has solid DB, network, threading support etc... It does a lot more then just cross-platform GUI (and it does most of it quite well).

Qt 肯定有可靠的数据库、网络、线程支持等......它比跨平台 GUI 做得更多(而且它大部分做得很好)。

I'd recommend it over GTK+.

我会推荐它而不是 GTK+。

回答by Slartibartfast

It probably depends on what you want to do. I would recommend Qt, because it's more than GUI, it has nice Python bindings (so does Gtk), and GUI libraries themselves are (subjectively speaking) more pleasant then Gtk.

这可能取决于你想做什么。我会推荐 Qt,因为它不仅仅是 GUI,它有很好的 Python 绑定(Gtk 也是如此),而且 GUI 库本身(主观上来说)比 Gtk 更令人愉快。

Gtk is on the other hand more common in linux world, so you can probably get more help on the web. Reason for widespread of Gtk probably has more to do with Gnome and Ubuntu, rather then technical merits, but if you want you software to blend nicely with those two, you'll achieve that more easily with Gtk.

另一方面,Gtk 在 linux 世界中更常见,因此您可能可以在网络上获得更多帮助。Gtk 广泛流行的原因可能更多地与 Gnome 和 Ubuntu 有关,而不是技术优点,但是如果您希望您的软件与这两者很好地融合,那么使用 Gtk 会更容易实现。

回答by Gregor Petrin

Just adding QT advantages to other answers.. QT has great documentation, its own IDE & GUI creatorand enhances C++ with some new concepts like slots/signals (basically events).

只是将 QT 的优势添加到其他答案中。 QT 有很好的文档,它自己的IDE 和 GUI 创建者,并通过一些新概念增强了 C++,比如插槽/信号(基本上是事件)。

I am not a GTK developer, so I can't compare those to the GTK world :(

我不是 GTK 开发人员,所以我无法将它们与 GTK 世界进行比较:(

回答by ngm

I have never used GTK, but from my personal experience using Qt:

我从未使用过 GTK,但根据我使用 Qt 的个人经验:

It is much more than a simple GUI. It's a whole application framework. I used to think of it as the Java libraries for C++. It provides all you mention -- database, XML, networking and threading, and more. It also provides things such as containers and iterators, and counterparts to a number of boost libraries.

它不仅仅是一个简单的 GUI。这是一个完整的应用程序框架。我曾经认为它是 C++ 的 Java 库。它提供了您提到的所有内容——数据库、XML、网络和线程,等等。它还提供诸如容器和迭代器之类的东西,以及许多 boost 库的对应物。

The thing that impressed me most when starting to use Qt was the extremely extensive documentation. You get a program called Qt Assistant, which provides fully indexed and searchable API documentation on your desktop, as well as numerous code examples and tutorials. I found it made a big difference in searching the web each time for API info. Very quick access when you need to remember a method signature.

在开始使用 Qt 时,给我印象最深的是极其广泛的文档。您将获得一个名为 Qt Assistant 的程序,它在您的桌面上提供完全索引和可搜索的 API 文档,以及大量代码示例和教程。我发现每次在网络上搜索 API 信息都会产生很大的不同。当您需要记住方法签名时非常快速地访问。

I am not sure which is most common; that's probably hard to measure accurately. They're certainly both popular. As Gnome is the default desktop of Ubuntu, and Gnome sits on top of GTK, it obviously has widespread usage. Of course, KDE is very popular as well. Nokia is heavily pushing Qt in the mobile space -- their Maemo OS, used on the new N900 for example, is soon to switch to Qt as the default toolkit (currently it is GTK.) I believe Qt will also soon become the default toolkit for Symbian OS.

我不确定哪个是最常见的;这可能很难准确测量。他们当然都很受欢迎。由于 Gnome 是 Ubuntu 的默认桌面,而 Gnome 位于 GTK 之上,显然它有着广泛的用途。当然,KDE 也很受欢迎。诺基亚正在移动领域大力推动 Qt——例如,他们在新 N900 上使用的 Maemo 操作系统很快就会切换到 Qt 作为默认工具包(目前​​是 GTK。)我相信 Qt 也将很快成为默认工具包对于 Symbian 操作系统。

I have not used Qt Creator, but I have heard many good things about it. It is a C++ IDE with obvious heavy integration with Qt. It also has fake vim emulation which is always nice if you like that kind of thing!

我没有使用过 Qt Creator,但我听说过很多关于它的好消息。它是一个 C++ IDE,明显与 Qt 高度集成。它还有假的 vim 仿真,如果你喜欢那种东西,它总是很好!

Qt uses qmake for build configuration. I found this much nicer than having to write your own makefiles. I do not know what GTK uses for building.

Qt 使用 qmake 进行构建配置。我发现这比必须编写自己的 makefile 好得多。我不知道 GTK 用于构建什么。

A couple of things I found a bit offputting with Qt at first was its big uses of preprocessor macros. The signal/slots system provides a nice mechanism for event/message passing in your application, but it does feel a bit like magic that may not be easily portable to another toolkit if you ever want to. Also, the moc (meta-object compiler), while I'm not entirely sure what it does, also feels a bit too much like magic going on behind the scenes.

起初我发现 Qt 有点令人反感的一些事情是它大量使用预处理器宏。信号/槽系统为您的应用程序中的事件/消息传递提供了一种很好的机制,但它确实有点像魔术,如果您愿意,可能不容易移植到另一个工具包。此外,moc(元对象编译器)虽然我不完全确定它的作用,但也感觉有点像幕后发生的魔法。

All in all, though, I would recommend Qt, particularly if you are learning. It has really amazing documentation and a nice IDE, and busy forums. You'll be able to build C++ apps very rapidly with it, particularly with the QML coming in 4.7.

不过,总而言之,我会推荐 Qt,特别是如果您正在学习。它有非常棒的文档和不错的 IDE,以及繁忙的论坛。您将能够使用它非常快速地构建 C++ 应用程序,尤其是使用 4.7 中的 QML。

回答by rui

I've used GTK+, QT and wxWidgets before. Here's a brief summary:

我以前使用过 GTK+、QT 和 wxWidgets。下面是一个简短的总结:

For my first cross platform UI project I decided to go for wxWidgets mainly because at the time the license wasn't as restrictive as QT's (QT was GPL and only for Linux) and it had platform specific UI (unlike GTK). The project worked out well but there were quite a few glitches getting it to compile and run properly in other platforms - sometimes some events were fired up differently and such. Also GDI in wxWidgets was pretty slow.

对于我的第一个跨平台 UI 项目,我决定使用 wxWidgets,主要是因为当时的许可证不像 QT 那样严格(QT 是 GPL,仅适用于 Linux)并且它具有特定于平台的 UI(与 GTK 不同)。该项目运行良好,但要使其在其他平台上正确编译和运行时出现了很多小故障 - 有时某些事件会以不同的方式启动,诸如此类。wxWidgets 中的 GDI 也很慢。

Next I used GTK for a different project in python. For this I used the python bindings and everything worked out more or less smoothly. I didn't quite like the fact that the UI didn't look native on Windows and Mac and also when you launch a GTK+ app it always debug outputs loads of CRITICAL warnings which seem fine to ignore. :S

接下来我将 GTK 用于 Python 中的另一个项目。为此,我使用了 python 绑定,一切都或多或少地顺利进行。我不太喜欢这样一个事实,即 UI 在 Windows 和 Mac 上看起来不是原生的,而且当你启动 GTK+ 应用程序时,它总是调试输出负载的 CRITICAL 警告,这些警告似乎可以忽略。:S

Finally, I did a very simple QT project now that Nokia has acquired it and was brilliant. The best of the three. First off, if you're not an old schooler who prefers VI or Emacs, QtCreator is brilliant. I really love VI and used it for years but I much prefer QtCreator for C++ QT projects. Regarding the library I also liked a lot the documentation and the APIs provided. QT has a concept of slots and signals which introduce new C++ keywords and a preprocessor. Basically, after reading a tutorial you'll get it easily and will start to love it. I'm now doing iPhone dev and it does feel a bit like Cocoa's/Interface Builder's UI paradigm.

最后,我做了一个非常简单的 QT 项目,现在诺基亚已经收购了它并且非常出色。三者中最好的。首先,如果您不是喜欢 VI 或 Emacs 的老学生,QtCreator 非常棒。我真的很喜欢 VI 并使用它多年,但我更喜欢用于 C++ QT 项目的 QtCreator。关于库,我也很喜欢提供的文档和 API。QT 有槽和信号的概念,它们引入了新的 C++ 关键字和预处理器。基本上,在阅读教程后,您会很容易掌握并开始喜欢上它。我现在在做 iPhone 开发,感觉有点像 Cocoa/Interface Builder 的 UI 范式。

Summary: I'd go for QT hands down. The license is pretty good and the SDK and documentation really nice.

总结:我会毫不犹豫地选择 QT。许可证非常好,SDK 和文档非常好。

回答by jlru

It also looks like Nokia is about to use Qt everywhere, like on Maemo

看起来诺基亚即将在任何地方使用 Qt,就像在 Maemo 上一样

回答by Detro

Qt. It's not only object oriented, is "good" object oriented. It's based on a "subset" of C++ that doesn't rely on the obscurity of C++ (but you are allowed to stick with them, if you fancy masochism ;) ).

Qt。它不仅是面向对象的,还是“好”的面向对象。它基于 C++ 的一个“子集”,它不依赖于 C++ 的晦涩(但如果你喜欢受虐狂,你可以坚持使用它们;))。

It has a strong momentum now that Nokia bought it (actually Nokia did ~2/3 years ago). It's going to be in all Nokia AND Intel mobile devices (smartphones, netbooks, tablets).

现在诺基亚收购了它,势头强劲(实际上诺基亚在大约 2/3 年前就这样做了)。它将出现在所有诺基亚和英特尔移动设备(智能手机、上网本、平板电脑)中。

It's the backbone of KDE, so it's very mature, but it's designed in a very flexible way, that makes it possible to support TODAY all the latest "cool stuff" that a more-then-just-GUIframework should have.

它是 KDE 的支柱,所以它非常成熟,但它以非常灵活的方式设计,这使得今天可以支持更多-然后只是 GUI框架应该具有的所有最新“酷东西” 。

Go for it.

去吧。

回答by trusktr

If you want your app to run on iOS, Android, Blackberry, other mobile platforms, Windows, Mac OSX, and Linux, use Qt.

如果您希望您的应用程序在 iOS、Android、Blackberry、其他移动平台、Windows、Mac OSX 和 Linux 上运行,请使用 Qt。

qt-project.org

qt-project.org