amanda45 amanda45 - 1 year ago 470
C++ Question

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();;
return a.exec();

Answer Source

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:

target_link_libraries(${targetName} Qt5::Charts)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download