Can't include <QtCharts/QLineSeries>

天涯浪子 提交于 2020-05-08 04:12:30

问题


It seems I can't find a way to include <QtCharts/QLineSeries> in my header so Qt knows about the QLineSeries class.

  • I added Qt += charts to my .pro file.
  • I added #include <QtCharts/QLineSeries> to MainWindow.h
  • Then I delete .pro.user file and any builds I've done. And then reopen the .pro file to reconfigure the project in the cleanest way.
  • Finally I set the build mode to Release, run QMake by right-clicking the project and selecting it and Run it.

I get the message:

 ...\PlottingCharts\mainwindow.h:14: error: 'QLineSeries' does not name a type
     QLineSeries *series;
     ^

So clearly Qt doesn't know anything about QLineSeries.

For reference, the linechart and openglseries examples work correctly.

Any one knows what I'm missing?


回答1:


As I wrote the question I found the answer.

I was missing using namespace QtCharts; in the header file. Got the reference from: http://doc.qt.io/qt-5/qtcharts-index.html




回答2:


If you want to avoid specifying the namespace, you can also declare your variable as:

QtCharts::QLineSeries *series;

With this solution you always have to prepend QtCharts::, but you also know your scope and the origin of your calls.



来源:https://stackoverflow.com/questions/38802982/cant-include-qtcharts-qlineseries

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!