c++qtchartsqt5.8

Using QChart in visual studio


I am trying to use the Qt QChart to plot a line graph. I am using visual Studio 2013 with Qt 5.8. I created a simple QApplication. When I paste QLineSeries *series it says QLineSeries is undefined. How can I fix this?

#include "QtGuiApplication2.h"
#include <QtWidgets/QApplication>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QtGuiApplication2 w;

    QLineSeries *series = new QLineSeries();

    w.show();
    return a.exec();
}

Solution

  • you need to link against QT5Charts under:

    general properties
    - Linker
      - Input
       - add the path: e.g. C:\Libraries\Qt\Qt5.7.0\msvc\lib\Qt5Chartsd.lib
    

    I suppose, you don't forget to add the namespace?

    using namespace QtCharts;
    

    if you work with cmake, just add this to your cmake file:

    find_package(Qt5Charts)
    target_link_libraries(${targetName} Qt5::Charts)