【问题标题】:How to fix "QtCharts" library file not found/can't include <QtCharts>? [duplicate]如何修复“QtCharts”库文件未找到/不能包含 <QtCharts>? [复制]
【发布时间】:2019-06-09 22:46:56
【问题描述】:

我是 Qt GUI/Widget 应用程序的新手,我正在尝试制作一个简单的条形图。我试图复制 QT 在他们的网站上提供的完全相同的代码,[链接]:https://doc-snapshots.qt.io/qt5-5.11/qtcharts-barchart-example.html#creating-bar-charts。但是,我不断收到很多错误消息,上面写着“QtCharts”文件未找到和“QBarSet”“QLegend”未找到,基本上所有包含的库都没有找到。

我在 QT 网站上看到了一些故障排除页面,它说我必须在我的 .qml 文件中添加一些导入语句。但我似乎无法找到 .qml 文件的位置? [链接]:https://doc.qt.io/qt-5/qtcharts-index.html

我的代码看起来完全像这样:

//main.cpp
----------
[link]: https://doc-snapshots.qt.io/qt5-5.11/qtcharts-barchart-main-cpp.html
//.pro file
------------
QT       += core gui charts
//I only add "charts" in the above line from the original .pro file
//everything else is the exact same .pro file as in the original.

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = testing_file
TEMPLATE = app
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
        main.cpp \
        mainwindow.cpp

HEADERS += \
        mainwindow.h

FORMS += \
        mainwindow.ui

您如何修复/使代码正常工作?我真的不知道如何修复错误消息。谢谢!

【问题讨论】:

  • 你是如何安装 Qt 的?
  • 当然可以。你到底想说什么?
  • Qt 有多种安装方式,如果您使用过在线安装程序,则必须启用子模块 Qt Charts,因为默认情况下它是禁用的,因此不会安装子模块,请参阅stackoverflow.com/questions/41625233。如果您使用了其他表格,则必须注明。
  • 我明白了。我有点忘记了如何安装 QT,但如果我没记错的话,我只是启用了 QT 提供的默认子模块。但是,如果您已经安装了 QT,如何启用/添加子模块 QT Charts?
  • 如果您使用在线安装程序安装,则只需运行该安装程序并运行该子模块,就像您重新安装它一样。如果您使用了另一种方法,那么您必须指出,因为以前的方法不是解决方案。

标签: c++ qt qt5


【解决方案1】:

我刚刚意识到我没有安装 eyllanesc 提到的 QT Charts 的组件/子模块。我不得不重新安装 QT 并启用 QT Charts 组件。您可以使用 QT 维护工具添加它,但我没有它,所以我只是重新安装它,因为我仍然有安装程序。

参考:How to include the QtCharts library in Qt Creator 4.2.0 (Community)

【讨论】:

  • 我已经使用了Qt Maintenance,但错误仍然存​​在,您能帮忙吗?
猜你喜欢
  • 2016-12-12
  • 2017-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-13
  • 2017-08-09
  • 2017-01-10
  • 1970-01-01
相关资源
最近更新 更多