Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QChart initialization error...
Forum Updated to NodeBB v4.3 + New Features

QChart initialization error...

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 303 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    potatolover9x
    wrote on last edited by
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • P potatolover9x

      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.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @potatolover9x
      Did you try moving the creation of the QChart (and all the rest of the QLineSeries stuff) after the QApplication a(myargc, myargv);? That should be essentially the first statement in a Qt program, before you instantiate any Qt objects.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved