使用 C++ 的图形用户界面?还是 C# 和 Java 的路要走?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3361405/
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
GUI with C++ ? or C# and Java the way to go?
提问by Ahmed
I am nearly done with a course about using OOP in C++ and all the programs we wrote in that course were console applications . I also finished a university course in C programming so I think I have solid C programming basics and now is the time to make a big step towards GUI .
我几乎完成了关于在 C++ 中使用 OOP 的课程,我们在该课程中编写的所有程序都是控制台应用程序。我还完成了 C 编程的大学课程,所以我认为我有扎实的 C 编程基础,现在是向 GUI 迈出一大步的时候了。
I did a lot of googling and each time I read more pages I get more confused , I learned that there were too famous options in the past which are WinAPI and MFC. I tried to look into the WinAPI but It seems pretty tough and needs a lot of time so I asked my instructor's advice and he told me that If I wanna write GUI programs I would better learn C# or Java rather than using C++ which is faster but better designed for low level programming applications like drivers and so . So I searched the web to find if C++ is still used in writing nowadays applications and to my surprise Firefox, Google Chrome, Notepad++ and many other GUI applications on sourceforge.netare written in C++ in contradiction with my instructor's advice. Also I learned that you can use QT or GTK libraries to build GUI applications in C++ but I have no idea ow to do that or if that is true.
我做了很多谷歌搜索,每次阅读更多页面时,我变得更加困惑,我了解到过去有太多著名的选项,即 WinAPI 和 MFC。我试图研究 WinAPI 但它看起来很困难而且需要很多时间所以我问了我导师的建议他告诉我如果我想编写 GUI 程序我最好学习 C# 或 Java 而不是使用 C++ 更快但更好地设计用于驱动程序等低级编程应用程序。所以我在网上搜索了 C++ 是否仍然用于编写当今的应用程序,令我惊讶的是 Firefox、Google Chrome、Notepad++ 和sourceforge.net上的许多其他 GUI 应用程序是用 C++ 编写的,与我导师的建议相矛盾。我还了解到您可以使用 QT 或 GTK 库在 C++ 中构建 GUI 应用程序,但我不知道该怎么做,或者这是否属实。
So My question is what are the nowadays best available options to write GUI programs efficiently no matter how steep is the learning curve. I googled for C++ GUI options because It think it will be faster than Java or C# apps, If anyone has a different opinion state it please.
所以我的问题是,无论学习曲线有多陡峭,目前有效编写 GUI 程序的最佳可用选项是什么。我在谷歌上搜索了 C++ GUI 选项,因为它认为它会比 Java 或 C# 应用程序更快,如果有人有不同的意见,请说明。
采纳答案by Blub
The fastest way is to use C# and WPF. It's fast and simple for small applications but can be pretty complex in my opinion and there is a lot to learn. At least you are future proof, Microsoft is pushing WPF themselves finally. (Visual Studio uses it, and there will be a lot more versions to come) The only real downside is, that you will only be able to run the application in Windows.
最快的方法是使用 C# 和 WPF。对于小型应用程序来说,它既快速又简单,但在我看来可能非常复杂,而且有很多东西需要学习。至少你是未来的证明,微软最终正在推动 WPF 自己。(Visual Studio 使用它,以后还会有更多版本)唯一真正的缺点是,您将只能在 Windows 中运行该应用程序。
If you really want the "low level" access, there a lot of interop options with C++ code.
如果您真的想要“低级别”访问,那么 C++ 代码有很多互操作选项。
回答by Artyom
First of all, if you want to lean to write platform independent GUI then C# is no go.
首先,如果你想编写独立于平台的 GUI,那么 C# 是不行的。
When you write GUI in C++ there is a question of toolkit, Qt and GTKmm provide you very solid cross platform toolkits. While Qt has more "native" look and feel on Windows than GTKmm, Java Swing allows you to write very good GUI as well but it would be heavier and slower then one written with Qt or GTKmm.
当您用 C++ 编写 GUI 时,会有一个工具包问题,Qt 和 GTKmm 为您提供了非常可靠的跨平台工具包。虽然 Qt 在 Windows 上比 GTKmm 具有更多“原生”外观和感觉,但 Java Swing 也允许您编写非常好的 GUI,但它比用 Qt 或 GTKmm 编写的更重和更慢。
Now... C#/WPF same issues as Java GUI - slower then native, but also it also locks you on one platform only.
现在... C#/WPF 与 Java GUI 相同的问题 - 比本机慢,但它也只能将您锁定在一个平台上。
My personal advice start from Qt.
我的个人建议从 Qt 开始。
回答by Alexander Beletsky
If you are new to GUI programming C#/WinForms will be best for you. It rather simple, have a great community around it, have a lot of ready-to-use controls.. and best documentation ever - MSDN.
如果您不熟悉 GUI 编程,C#/WinForms 将最适合您。它相当简单,周围有一个很棒的社区,有很多现成的控件......和有史以来最好的文档 - MSDN。
Sure, if you are looking for deep knowledge of "how things works" you then have to understand Win32 GUI. So, you can always back to C++/MFC for that. I would not suggest any other C++ libraries (as Qt), not because they are bad, but because they require good experience to start up.
当然,如果您正在寻找“事物如何工作”的深入知识,那么您必须了解 Win32 GUI。因此,您始终可以为此返回 C++/MFC。我不会推荐任何其他 C++ 库(如 Qt),不是因为它们不好,而是因为它们需要良好的启动经验。
My suggestion is start with WinForms, undestand the basic and learn to create simple application. As soon as you are master in that, go deeper :)
我的建议是从 WinForms 开始,了解基础并学习创建简单的应用程序。一旦你掌握了这方面的知识,就更深入:)
回答by Blub
It depends on what kind of GUI application you want to write. If you want to write a shrink-wrapped app like MS Word or Firefox, then C++ is the way to go, because the market demands the last little bit of performance, with minimal dependencies. OTOH, if you want to write (for example) an interface to your company's database, the performance of the GUI is normally not important, but delivering something quickly and cheaply is, so you should use something more RAD, like C#.
这取决于您要编写什么样的 GUI 应用程序。如果您想编写像 MS Word 或 Firefox 那样的压缩包装应用程序,那么 C++ 是您要走的路,因为市场需要最后一点性能,并且依赖最少。OTOH,如果您想编写(例如)公司数据库的接口,GUI 的性能通常并不重要,但快速且廉价地交付一些东西很重要,因此您应该使用更多 RAD 的东西,例如 C#。
回答by n0rd
Qt is very good. People say WTL is also nice, but I didn't used it.
Qt 非常好。人们说WTL也不错,但我没用过。
Java and GUI does not fit very well in my head. There are some native to Java GUI libraries (AWT, Swing) but they are slow and don't provide interface native to platform it runs on. There is also SWT, which is used by Eclipse, but haven't seen any app besides Eclipse using it.
Java 和 GUI 不太适合我的想法。有一些 Java GUI 库(AWT、Swing)本机,但它们速度很慢,并且不提供运行平台的本机接口。还有SWT,Eclipse用的,不过没见过除了Eclipse用的app。
If GUI needs are simple I'd stick to C#: you drop some controls on your form, write some logics behind it and you are ready to go. If you need some really complex GUI then I don't think there would be a huge difference in development time between different languages.
如果 GUI 需求很简单,我会坚持使用 C#:您在表单上放置一些控件,在其背后编写一些逻辑,然后就可以开始了。如果您需要一些非常复杂的 GUI,那么我认为不同语言之间的开发时间不会有很大差异。
回答by computinglife
C++ is good for speed (HTML rendering tools like chrome / firefox or image editors like photoshop) and for performing "feats" you might not otherwise be able to do on other platforms.
C++ 有利于速度(HTML 渲染工具,如 chrome / firefox 或图像编辑器,如 photoshop)和执行“壮举”,否则您可能无法在其他平台上做到这一点。
But it is more painful to use and there is much more of a luearning curve on any of the C++ based UI libraries than you would care to learn.
但是使用起来更痛苦,而且任何基于 C++ 的 UI 库的学习曲线都比您愿意学习的要多得多。
Since you do not seem to require any of this, as is clear from your question, your default choice should be C# or Java or Web based like your tutor advised.
由于您似乎不需要任何这些,从您的问题中可以清楚地看出,您的默认选择应该是 C# 或 Java 或基于 Web 的,就像您的导师建议的那样。
回答by Truong Ha
C++ never dies, so that learning it is not a wrong decision. However, it is quite difficult to write GUI applications using C++ during early days. Therefore, I suggest you to use C# t write some GUI applications before switching back to C++.
C++ 永远不会消亡,因此学习它并不是一个错误的决定。然而,早期使用 C++ 编写 GUI 应用程序是相当困难的。因此,我建议您在切换回 C++ 之前使用 C# t 编写一些 GUI 应用程序。
回答by Flot2011
Not exactly an answer to your question, but if you are still in learning and not in the production line, try learning Win API. Actually, I am surprised nobody told you that.
不完全是您问题的答案,但如果您仍在学习而不是在生产线上,请尝试学习 Win API。事实上,我很惊讶没有人告诉你。
You see, all other frameworks /API /SDKs are actually just wrappers around this API, and chances are that whenever you are asked to do something non-standard in your GUI you will not find a solution within your framework and will need to dig down to Win API anyway.
你看,所有其他框架 /API /SDK 实际上只是这个 API 的包装器,而且很有可能每当你被要求在你的 GUI 中做一些非标准的事情时,你将无法在你的框架中找到解决方案,需要深入挖掘无论如何都要赢得API。
Yes, it is Windows only API, still knowing what is actually going on behind the scene may be very handy at times.
是的,它只是 Windows 的 API,但仍然知道幕后实际发生的事情有时可能非常方便。
Just my 2 cents.
只有我的 2 美分。
回答by Oleg Kolosov
If you have c++ foundation and want to expand that I recommend to start from Qt. It's distribution includes graphical UI designer and Asistant - browser for documentation. There is also separate product Qt Creator - complete IDE tailored for Qt which have everything integrated (including compiler). All of this if free and really easy to setup. Excellent tutorials included. Qt also includes non gui classes for common programming problems (like containers, variant type, etc.). You can convert your console application to GUI in a matter of few hours and decide if you want to continue learn it or try some other toolkit.
如果您有 C++ 基础并想要扩展,我建议您从 Qt 开始。它的发行版包括图形 UI 设计器和 Asistant - 文档浏览器。还有单独的产品 Qt Creator - 为 Qt 量身定制的完整 IDE,其中集成了所有内容(包括编译器)。所有这一切都是免费的,而且非常容易设置。包括优秀的教程。Qt 还包括用于常见编程问题(如容器、变体类型等)的非 gui 类。您可以在几个小时内将您的控制台应用程序转换为 GUI,并决定是继续学习它还是尝试其他一些工具包。
Just go to http://qt.nokia.com/downloadsdownload SDK, install it and you have everyting to start coding.
只需访问http://qt.nokia.com/downloads下载 SDK,安装它,您就可以开始编码了。

