C++ 用于创建 GUI(gtk、qt、win32 api 等)的最佳库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4048231/
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-28 14:22:09  来源:igfitidea点击:

Your best library for create GUI ( gtk, qt, win32 api, etc )?

c++windowsgtk

提问by xRobot

In your opinion, what is the best way to create gui in Windows? with gtk or win32 api ?

在您看来,在Windows 中创建 gui 的最佳方法是什么?使用 gtk 或 win32 api 吗?

Do you recommend GTK for windows ? Yes ? NO ? Why ?

你推荐 Windows 的 GTK 吗?是的 ?不 ?为什么 ?

采纳答案by EboMike

Let's see.

让我们来看看。

  • Win32 is very low-level, C based, and awkward to use.
  • MFC is considered obsolete.
  • C# (or C++) with .NET is probably your primary choice for Windows-specific development.
    • There are even semi-limited ways to port that code to other platforms (Mono).
  • Java is great for very platform-independent code that "just runs".Sorry, you said C++.
  • QT is relatively platform-independent.
  • GTK+, of course, although I personally don't have much experience with it.
  • Win32 是非常低级的,基于 C 的,并且使用起来很笨拙。
  • MFC 被认为已经过时。
  • 带有 .NET 的 C#(或 C++)可能是 Windows 特定开发的主要选择。
    • 甚至有一些有限的方法可以将该代码移植到其他平台(Mono)。
  • Java 非常适合“直接运行”的非常独立于平台的代码。抱歉,你说的是 C++。
  • QT 相对独立于平台。
  • GTK+,当然,虽然我个人没有太多的经验。

Personally, if I do something Windows-specific, I use .NET - the tools in Visual Studio are very powerful, and it's a great all-encompassing suite.

就我个人而言,如果我做一些特定于 Windows 的事情,我会使用 .NET - Visual Studio 中的工具非常强大,而且它是一个很棒的包罗万象的套件。

For platform-independent stuff, I use Java, but that may not be your tool of choice. I've seen QT used a lot for that purpose.

对于平台无关的东西,我使用 Java,但这可能不是您的首选工具。我已经看到 QT 为此目的使用了很多。

回答by Burning Prodigy

If you are making the gui only for windows, I would strongly recommend WIN 32 Api. I have Made many applications in GTK+ , pyGtk , FLTK and have learned Qt, MFC and SmartWin++. Believe me , But I like Win32 Api the best. It may have a steep learning curve, but for creating native windows applications , it is the fastest and the BEST. And the more complex youre program gets, the easier Win32 Api is compared to other toolkits. And there are things you can do in Win32 Api, which you can not do in any other toolkit.

如果您只为 Windows 制作 gui,我强烈推荐 WIN 32 Api。我在 GTK+ 、 pyGtk 、 FLTK 中做了很多应用,并且学习了 Qt、MFC 和 SmartWin++。相信我,但我最喜欢 Win32 Api。它可能有一个陡峭的学习曲线,但对于创建本机 Windows 应用程序,它是最快和最好的。您的程序越复杂,与其他工具包相比,Win32 Api 就越容易。还有一些你可以在 Win32 Api 中做的事情,而你在任何其他工具包中都做不到。

TESTED:

测试:

starting time (simple gui with menu and buttons): GTK+ = 7 secs; Qt = 4 secs; WxWidgets = 3.32 seconds; FLTK = 1 second; Win32 Api = 0.34 seconds;

开始时间(带有菜单和按钮的简单 gui):GTK+ = 7 秒;Qt = 4 秒;WxWidgets = 3.32 秒;FLTK = 1 秒;Win32 API = 0.34 秒;

space taken: Gtk+ = 132 kb; Qt = 4.5 mb; WxWidgets = 4.5 mb; FLTK = 54 kb; Win32 Api = 6.5 kb;

占用空间:Gtk+ = 132 kb;Qt = 4.5 mb;WxWidgets = 4.5 mb;FLTK = 54 kb;Win32 API = 6.5 kb;

回答by Christian

You really have a lot of GUI toolkits/frameworks to choose from: Qt, wxWidgets, GTK+/gtkmm, WinAPI, MFC, .NET WinForms/WPF... and those are only the popular ones.

你真的有很多 GUI 工具包/框架可供选择:Qt、wxWidgets、GTK+/gtkmm、WinAPI、MFC、.NET WinForms/WPF……而这些只是流行的。

Since you limit yourself to C++, I'd strike out .NET because C++ on .NET is intended to serve as a connection between the unmanaged and managed world. That doesn't mean you can't use it for other types of development, but given the awkward syntax and countless pitfalls I'd not go with it. Moreover, the WinForms code generator of VS puts the forms' code into the header file.. brrrr

由于您将自己限制在 C++ 中,我会删除 .NET,因为 .NET 上的 C++ 旨在充当非托管和托管世界之间的连接。这并不意味着您不能将它用于其他类型的开发,但考虑到笨拙的语法和无数的陷阱,我不会使用它。此外,VS 的 WinForms 代码生成器将表单的代码放入头文件中.. brrrr

As others have stated, WinAPI is written in C, very fast and powerful, but very low level and not easy to program/learn. MFC would be an option since it's written in C++, easier to use than WinAPI and also very powerful. However, it's pretty much obsolete (due to the presence of .NET, mostly).

正如其他人所说,WinAPI 是用 C 语言编写的,非常快速且功能强大,但非常低级且不易编程/学习。MFC 将是一种选择,因为它是用 C++ 编写的,比 WinAPI 更易于使用并且功能也非常强大。但是,它几乎已经过时了(主要是由于 .NET 的存在)。

I wouldn't recommend GTK+/gtkmm (a C++ wrapper for GTK+) for Windowssince you don't get the native windows look, it's rather annoying to set up on your developer machine and it also drags around tons of dependencies that you have to install on the user machine. That's actually a pity because especially gtkmm has a very beautiful class hierarchy and design. Probably one of the best designed GUI libraries :)

我不会为 Windows推荐 GTK+/gtkmm(GTK+ 的 C++ 包装器)因为您没有获得本机 Windows 的外观,在您的开发人员机器上进行设置相当烦人,而且它还拖累了您必须处理的大量依赖项安装在用户机器上。这其实很可惜,因为特别是 gtkmm 有一个非常漂亮的类层次结构和设计。可能是设计最好的 GUI 库之一 :)

That said, what would I recommend? Either Qt or wxWidgets. Both are written in (fairly modern) C++, actively developed, have a good library design, run multi-platform and offer lots of functionality. In any case, play around with a few of the libraries listed in the answers here and see which one lets you do the things you want to do most easily :)

也就是说,我会推荐什么?Qt 或 wxWidgets。两者都是用(相当现代的)C++ 编写的,积极开发,具有良好的库设计,运行多平台并提供大量功能。无论如何,请使用此处答案中列出的一些库,看看哪个库可以让您最轻松地完成您想做的事情:)

回答by fangzhzh

win32 api is too complicated, MFC is too annoying. I have used MFC, win32api, and Qt in windows. In my opnion, Qt is the best one. I havent tried GTK, so sorry knowing nothing about it.

win32 api太复杂了,MFC太烦了。我在 Windows 中使用过 MFC、win32api 和 Qt。在我看来,Qt 是最好的。我还没有尝试过 GTK,很抱歉对此一无所知。

Edit 2019: It looks all these options are outdated, how about the cross-platform solutions, react-native windows, electron

2019 年编辑:看起来所有这些选项都是outdated,跨平台解决方案,react-native windowselectron怎么样?

回答by M3t0r

both are for c, but there is a good wrapper for gtk (gtkmm).

两者都用于 c,但是 gtk (gtkmm) 有一个很好的包装器。

gtk has its own look, so theres no skinning of ui elements on the user side(with windows styles). but i like to programm with it more.

gtk 有自己的外观,所以用户端没有 ui 元素的皮肤(使用 windows 样式)。但我更喜欢用它编程。

win32, mfc, .net are mostly limited to ms visual studio, while gtk is very hard to use with vs.

win32、mfc、.net 大多仅限于 ms Visual Studio,而 gtk 很难与 vs. 一起使用。

you should have a look on win32, .net, gtkmm and qt. just try to write and compile a simple hello world program with them

你应该看看 win32、.net、gtkmm 和 qt。试着用它们编写和编译一个简单的 hello world 程序

upsides of win32:

win32的优点:

  • native windows code
  • fast
  • 本机窗口代码
  • 快速地

downsides:

缺点:

  • no classes, only c with handles (very crappy)
  • in my opinion very bad documented
  • 没有类,只有带手柄的 c(非常糟糕)
  • 在我看来非常糟糕的记录

upsides of gtk(mm):

gtk(mm) 的优点:

  • easy to learn/programm
  • good documented
  • 易于学习/编程
  • 有据可查

downsides:

缺点:

  • somehow difficult to install the development files
  • no native windows look
  • 安装开发文件有点困难
  • 没有本机窗口外观

回答by Bowie Owens

I have used GTK+ in the past for a multi-platform application. I found it relatively simple to learn and use. To my mind the main advantage of GTK+ is that you will be able to port your application to other windowing systems. And the main disadvantage is that it will not look exactly like other windows applications. If you are doing cross platform work or are already very familiar with GTK+ (and don't have time to spend learning a new toolkit), I would recommend it.

我过去曾将 GTK+ 用于多平台应用程序。我发现它的学习和使用相对简单。在我看来,GTK+ 的主要优点是您可以将您的应用程序移植到其他窗口系统。主要缺点是它看起来不像其他 Windows 应用程序。如果您正在做跨平台工作或者已经非常熟悉 GTK+(并且没有时间花时间学习新工具包),我会推荐它。

回答by Ralf

Personally I prefer Qt, but it really depends on what kind of user interfaces you want to make.

我个人更喜欢 Qt,但这实际上取决于您想要制作什么样的用户界面。

Against Win32:

针对 Win32:

  • low-level, high complexity to accomplish trivial things. You have to do EVERYTHING

  • if you go this route I would recomment a book like the one from Petzold.

  • 低级、高复杂度来完成琐碎的事情。你必须做任何事情

  • 如果你走这条路,我会推荐一本像Petzold那样的书。

Pro Qt:

专业Qt:

  • Good looking GUIs

  • Can change the look and feel very easily by creating stylesheets

  • Signal and slots mechanism notifies you of UI events such as "button clicked" etc.

  • Nice layout system

  • Integrated with Visual Studio IDE

  • Modern object oriented c++ code, easy to understand and use

  • Qt Assistant (Very good documentation)

  • Relatively liberal licensing (LGPL)

  • Qt Designer - WYSIWYG design tool you can use for form design

  • Comes with a wealth of other c++ functionality including XML, networking, eventloops, threading, database access, etc

  • 好看的图形用户界面

  • 可以通过创建样式表很容易地改变外观

  • 信号和插槽机制会通知您 UI 事件,例如“单击按钮”等。

  • 漂亮的布局系统

  • 与 Visual Studio IDE 集成

  • 现代面向对象的C++代码,易于理解和使用

  • Qt 助手(非常好的文档)

  • 相对宽松的许可 (LGPL)

  • Qt Designer - 可用于表单设计的 WYSIWYG 设计工具

  • 带有丰富的其他 C++ 功能,包括 XML、网络、事件循环、线程、数据库访问等

Against Qt:

对抗 Qt:

  • Intermediary step of using MOC compiler
  • 使用 MOC 编译器的中间步骤

Pro WPF:

专业 WPF:

  • if you want the new WPF capabilities of the new Windows platforms, WPF is the way to go.
  • 如果你想要新的 Windows 平台的新 WPF 功能,WPF 是要走的路。

回答by Seva Alekseyev

If Linux (or Mac) compatibility is your concern, then Qt. Else Win32.

如果您关心 Linux(或 Mac)兼容性,那么 Qt. 否则 Win32。

回答by bbosak

You may want to try Winforms or WPF. If you're limited to using C/C++, you can embed .NET code using the /clr option for the compiler to embed .NET code for Winforms or WPF. Sources:

您可能想尝试 Winforms 或 WPF。如果您仅限于使用 C/C++,则可以使用编译器的 /clr 选项嵌入 .NET 代码,以便为 Winforms 或 WPF 嵌入 .NET 代码。资料来源:

http://msdn.microsoft.com/en-us/library/k8d11d4s(VS.71).aspx
http://msdn.microsoft.com/en-us/library/ms754130.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.aspx
Personal experience

http://msdn.microsoft.com/en-us/library/k8d11d4s(VS.71).aspx
http://msdn.microsoft.com/en-us/library/ms754130.aspx
http://msdn.microsoft .com/en-us/library/system.windows.forms.form.aspx
个人经验

回答by Vantomex

For platform independent development, I would recommend Qt instead of the current GTK. GTK2 drawing was very slow compared to Qt as well as Win32. If you love native look feel, wxWidgetsis made for you.

对于平台独立开发,我会推荐 Qt 而不是当前的 GTK。与 Qt 和 Win32 相比,GTK2 的绘制速度非常慢。如果您喜欢原生外观,那么wxWidgets就是为您量身打造的