0

我是初学者是C++。我试图找到,是否可以在 QT 窗口和基于 Linux 的环境中运行我的程序。当用户登录我的系统时,用户可以选择GUI或终端模式来运行系统。

因此,我想知道是否有可能做到这一点。如果可能的话,我该如何继续?我应该使用什么命令从 QT 窗口切换到终端?我需要为单独或使用同一组类创建一组单独的项目吗?

4

2 回答 2

2

All Linux programs (unless explicitly disabled) print out text to a terminal. If you run the program in a graphical environment you will probably not run it from a console, therefore you won't see the output, but it will be still there.

If you want your program to be usable from a console, just test whether you could create the main window and if not, fallback to simple text output.

Note that the binary will still require the X server and Qt libraries to be installed.

于 2012-08-02T13:30:06.607 回答
0

您可以通过 QApplication 构造函数在启用或不启用 GUI 的情况下构建应用程序。请参阅 Qt 文档中的示例:

http://qt-project.org/doc/qt-4.8/qapplication.html#QApplication-2

不过,应该注意的是,Let_Me_Be 的回复中的所有内容都是正确的。事实上,Qt 示例完全符合他的建议。在你投入编码之前,请花时间理解他的答案。

于 2012-08-03T19:43:17.627 回答