【问题标题】:Why include QtWidgets for a command line application?为什么要在命令行应用程序中包含 QtWidgets?
【发布时间】:2013-10-17 03:38:40
【问题描述】:

我创建了一个简单的 Qt 控制台应用程序(基于 Qt 提供的示例代码)。虽然这是一个控制台应用程序,但 ldd 显示了许多链接的 X11 内容。

我注意到我的 .pro 文件中有 QT += widgets。这对于控制台应用程序来说似乎很奇怪,所以我删除了小部件但没有编译节目:

main.cpp:13:24: error: QApplication: No such file or directory
main.cpp: In function ‘int main(int, char**)’:
main.cpp:26: error: ‘QApplication’ was not declared in this scope
main.cpp:26: error: expected ‘;’ before ‘app’
main.cpp:47: error: ‘app’ was not declared in this scope
main.cpp: At global scope:
main.cpp:21: warning: unused parameter ‘argc’
main.cpp:21: warning: unused parameter ‘argv’
make: *** [main.o] Error 1

谁能告诉我发生了什么事?我是否需要控制台应用程序的小部件?如果没有,为什么我不能成功删除它?

【问题讨论】:

    标签: c++ qt console widget


    【解决方案1】:

    QApplication 是 Qt 5 中 QtWidgets 模块的一部分,所以如果你想使用它,那么你需要包含它。

    如果您根本不需要任何 GUI 内容,请改用 QCoreApplication。它在 QtCore 模块中,不需要包含精美的图形部分。

    【讨论】:

      猜你喜欢
      • 2014-04-14
      • 2017-01-21
      • 2010-11-10
      • 1970-01-01
      • 2012-01-29
      • 2021-11-02
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多