你能用 C++ 编写一个适用于 Windows 和 Linux 操作系统的 GUI 吗?

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

Can you program a GUI in C++ that works on both Windows and Linux operating systems?

c++windowslinuxvisual-studio-2010user-interface

提问by Landin Martens

I have been learning C++ for a while now, and so far I love it. But I have been stuck at the console application level. I have built C# programs for a few years so I love having a GUI and not do everything via console.

我已经学习 C++ 一段时间了,到目前为止我喜欢它。但是我一直停留在控制台应用程序级别。我已经构建了几年 C# 程序,所以我喜欢有一个 GUI,而不是通过控制台做任何事情。

Console programs when compiled will work on both windows and linux, which is great. When I was searching GUI C++ tutorials I could only find tutorials for windows specific GUI applications.

编译后的控制台程序可以在 windows 和 linux 上运行,这很棒。当我搜索 GUI C++ 教程时,我只能找到针对 Windows 特定 GUI 应用程序的教程。

So my question is this, can you program a GUI in C++ that when compiled with run on both windows and linux? If this is not possible, can someone point me to a great place to learn windows and linux GUI?

所以我的问题是,你能用 C++ 编写一个 GUI,当它在 windows 和 linux 上运行时编译吗?如果这是不可能的,有人能给我指出一个学习 windows 和 linux GUI 的好地方吗?

回答by vitakot

I suggest you to use Qt by Nokia:

我建议你使用诺基亚的 Qt:

http://qt.nokia.com/products/

http://qt.nokia.com/products/

It is free, very powerful, very easy to use, and well designed. And there is also a Visual Studio Add-in available:

它是免费的,非常强大,非常易于使用,并且设计精良。还有一个 Visual Studio 插件可用:

http://developer.qt.nokia.com/wiki/QtVSAddin

http://developer.qt.nokia.com/wiki/QtVSAddin

but you can use their own cross-platform IDE called Qt Creator as well.

但您也可以使用他们自己的跨平台 IDE,称为 Qt Creator。

回答by BizzyDizzy

You can use wxWidget library.

您可以使用wxWidget 库

回答by Charles

Yes, you need to use a cross platform GUI toolkit like WxWidgets

是的,您需要使用像 WxWidgets 这样的跨平台 GUI 工具包

回答by Jonathan Henson

回答by Basile Starynkevitch

Indeed, using cross-platform GUI libraries (like Qt, Gtk, WxWidgets) help you to have the same source code working on Linux and Windows. I recommend Qt if coding in C++.

事实上,使用跨平台 GUI 库(如 Qt、Gtk、WxWidgets)可以帮助您在 Linux 和 Windows 上使用相同的源代码。如果用 C++ 编码,我推荐 Qt。

But there is no way to build an executable working on both systems (unless you use wineto emulate Windows on Linux, which I don't recommend in your case).

但是没有办法在两个系统上构建一个可执行文件(除非你在 Linux 上使用wine来模拟 Windows,我不建议你这样做)。