QChart initialization error...
-
I am following the simple line chart example on Qt's website (found here: LineChart example).
I was receiving a strange Unhandled exception EXCEPTION_ACCESS_VIOLATION error, and I have isolated the cause of it.
The issue is this simple initializing line:
QChart *chart = new QChart(); // Trouble line
My main.cpp: (It is quite long so I removed all unnecessary functions)
#include <QPainter> #include <QPen> #include <QApplication> #include <QMainWindow> #include <QtCharts> // for QLineSeries #include <QChart> // for QChart #include <QGraphicsWidget> // added because it is the base class of QChart (does not fix) #include <QChartView> #include <iostream> int LineChart::OpenGraphic() { char *myargv[1]; int myargc = 1; myargv[0] = strdup(""); //QLineSeries *series = new QLineSeries(); //series->append(0, 6); //series->append(2, 4); //series->append(3, 8); //series->append(7, 4); //series->append(10, 5); //*series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); QChart *chart = new QChart(); // Trouble line //chart->legend()->hide(); //chart->addSeries(series); //chart->createDefaultAxes(); //chart->setTitle("Simple line chart example"); //QChartView *chartView = new QChartView(chart); //chartView->setRenderHint(QPainter::Antialiasing); QApplication a(myargc, myargv); QMainWindow w; //w.setCentralWidget(chartView); w.resize(400, 300); w.show(); return a.exec(); }
However, this does not seem to resolve the issue at all... I have seen this issue appear a few times in the Qt Forums, and I have not been able to fix it. I have checked the Properties of my Visual Studio Project, and I have already included the file \bin\Qt5Charts.lib within Linker > Input as well as \include\QtCharts\ within C++ > General.
I'm just trying to create a very simple line chart but initialization of QChart causes issues.
-
I am following the simple line chart example on Qt's website (found here: LineChart example).
I was receiving a strange Unhandled exception EXCEPTION_ACCESS_VIOLATION error, and I have isolated the cause of it.
The issue is this simple initializing line:
QChart *chart = new QChart(); // Trouble line
My main.cpp: (It is quite long so I removed all unnecessary functions)
#include <QPainter> #include <QPen> #include <QApplication> #include <QMainWindow> #include <QtCharts> // for QLineSeries #include <QChart> // for QChart #include <QGraphicsWidget> // added because it is the base class of QChart (does not fix) #include <QChartView> #include <iostream> int LineChart::OpenGraphic() { char *myargv[1]; int myargc = 1; myargv[0] = strdup(""); //QLineSeries *series = new QLineSeries(); //series->append(0, 6); //series->append(2, 4); //series->append(3, 8); //series->append(7, 4); //series->append(10, 5); //*series << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2); QChart *chart = new QChart(); // Trouble line //chart->legend()->hide(); //chart->addSeries(series); //chart->createDefaultAxes(); //chart->setTitle("Simple line chart example"); //QChartView *chartView = new QChartView(chart); //chartView->setRenderHint(QPainter::Antialiasing); QApplication a(myargc, myargv); QMainWindow w; //w.setCentralWidget(chartView); w.resize(400, 300); w.show(); return a.exec(); }
However, this does not seem to resolve the issue at all... I have seen this issue appear a few times in the Qt Forums, and I have not been able to fix it. I have checked the Properties of my Visual Studio Project, and I have already included the file \bin\Qt5Charts.lib within Linker > Input as well as \include\QtCharts\ within C++ > General.
I'm just trying to create a very simple line chart but initialization of QChart causes issues.
@potatolover9x
Did you try moving the creation of theQChart
(and all the rest of theQLineSeries
stuff) after theQApplication a(myargc, myargv);
? That should be essentially the first statement in a Qt program, before you instantiate any Qt objects.