Qt Charts: Access Violation exception



  • Hi there having a weird problem with QtCharts. I was following the example from here: https://doc.qt.io/qt-5/qtcharts-linechart-example.html
    but at the line where I declare
    QChart *chart = new QChart();
    It gives me the error:
    Exception thrown at 0x00007FF87757B51C (Qt5Gui.dll) in QtChartTest2.exe: 0xC0000005: Access violation reading location 0x0000000000000000.
    Which makes no sense to me. I isolated the line and it's seems that it is what is causing the error.
    I am using Visual Studio Community 2017 on windows 10 and I have included in the project properties the Qt5Charts dependencies, which I have included, like here: https://forum.qt.io/topic/69915/qtcharts-causing-linking-errors-lnk2019/11.

    I ran the same example in QtCreator and I am not having the same issue.

    I feel like I am missing something very obvious that I am missing.



  • @Cephas

    I don't know how is your implementation.

    You're trying to access a NULL pointer.

    Use static constructor instead, QChart chart(args);

    Kind Regards,

    Enrique Hdz



  • Could you post the stack trace?



  • @VRonin

    Qt5Gui.dll!initPalette() Line 219	C++	Symbols loaded.
     	Qt5Gui.dll!QGuiApplication::palette() Line 2961	C++	Symbols loaded.
     	Qt5Widgets.dll!QApplication::palette(const char * className) Line 1400	C++	Symbols loaded.
     	Qt5Widgets.dll!QWidgetTextControlPrivate::setContent(Qt::TextFormat format, const QString & text, QTextDocument * document) Line 437	C++	Symbols loaded.
     	Qt5Widgets.dll!QWidgetTextControlPrivate::init(Qt::TextFormat format, const QString & text, QTextDocument * document) Line 417	C++	Symbols loaded.
     	Qt5Widgets.dll!QWidgetTextControl::QWidgetTextControl(QObject * parent) Line 862	C++	Symbols loaded.
     	Qt5Widgets.dll!QGraphicsTextItemPrivate::textControl() Line 10531	C++	Symbols loaded.
     	Qt5Widgets.dll!QGraphicsTextItem::document() Line 10193	C++	Symbols loaded.
     	Qt5Charts.dll!QtCharts::ChartTitle::ChartTitle(QGraphicsItem * parent) Line 42	C++	Symbols loaded.
     	[Inline Frame] Qt5Charts.dll!QtCharts::ChartPresenter::createTitleItem() Line 241	C++	Symbols loaded.
     	Qt5Charts.dll!QtCharts::ChartPresenter::setTitleFont(const QFont & font) Line 338	C++	Symbols loaded.
     	Qt5Charts.dll!QtCharts::ChartThemeManager::decorateChart(QtCharts::QChart * chart, QtCharts::ChartTheme * theme) Line 107	C++	Symbols loaded.
     	Qt5Charts.dll!QtCharts::ChartThemeManager::setTheme(QtCharts::QChart::ChartTheme theme) Line 87	C++	Symbols loaded.
     	[Inline Frame] Qt5Charts.dll!QtCharts::QChart::setTheme(QtCharts::QChart::ChartTheme) Line 383	C++	Symbols loaded.
     	[Inline Frame] Qt5Charts.dll!QtCharts::QChartPrivate::init() Line 876	C++	Symbols loaded.
     	Qt5Charts.dll!QtCharts::QChart::QChart(QGraphicsItem * parent, QFlags<enum Qt::WindowType> wFlags) Line 250	C++	Symbols loaded.
    >	QtChartTest2.exe!QtChartTest2::weightsHist() Line 30	C++	Symbols loaded.
     	QtChartTest2.exe!QtChartTest2::qt_static_metacall(QObject * _o, QMetaObject::Call _c, int _id, void * * _a) Line 76	C++	Symbols loaded.
     	Qt5Cored.dll!QMetaObject::activate(QObject * sender, int signalOffset, int local_signal_index, void * * argv) Line 3768	C++	Symbols loaded.
     	Qt5Cored.dll!QMetaObject::activate(QObject * sender, const QMetaObject * m, int local_signal_index, void * * argv) Line 3629	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QAbstractButton::clicked(bool _t1) Line 310	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QAbstractButtonPrivate::emitClicked() Line 416	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QAbstractButtonPrivate::click() Line 408	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QAbstractButton::mouseReleaseEvent(QMouseEvent * e) Line 1011	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QWidget::event(QEvent * event) Line 8819	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QAbstractButton::event(QEvent * e) Line 969	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QPushButton::event(QEvent * e) Line 686	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QApplicationPrivate::notify_helper(QObject * receiver, QEvent * e) Line 3722	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QApplication::notify(QObject * receiver, QEvent * e) Line 3198	C++	Symbols loaded.
     	Qt5Cored.dll!QCoreApplication::notifyInternal2(QObject * receiver, QEvent * event) Line 1018	C++	Symbols loaded.
     	Qt5Cored.dll!QCoreApplication::sendSpontaneousEvent(QObject * receiver, QEvent * event) Line 236	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QApplicationPrivate::sendMouseEvent(QWidget * receiver, QMouseEvent * event, QWidget * alienWidget, QWidget * nativeWidget, QWidget * * buttonDown, QPointer<QWidget> & lastMouseReceiver, bool spontaneous) Line 2702	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QWidgetWindow::handleMouseEvent(QMouseEvent * event) Line 623	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QWidgetWindow::event(QEvent * event) Line 244	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QApplicationPrivate::notify_helper(QObject * receiver, QEvent * e) Line 3722	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QApplication::notify(QObject * receiver, QEvent * e) Line 3094	C++	Symbols loaded.
     	Qt5Cored.dll!QCoreApplication::notifyInternal2(QObject * receiver, QEvent * event) Line 1018	C++	Symbols loaded.
     	Qt5Cored.dll!QCoreApplication::sendSpontaneousEvent(QObject * receiver, QEvent * event) Line 236	C++	Symbols loaded.
     	Qt5Guid.dll!QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::MouseEvent * e) Line 1950	C++	Symbols loaded.
     	Qt5Guid.dll!QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate::WindowSystemEvent * e) Line 1734	C++	Symbols loaded.
     	Qt5Guid.dll!QWindowSystemInterface::sendWindowSystemEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 945	C++	Symbols loaded.
     	qwindowsd.dll!QWindowsGuiEventDispatcher::sendPostedEvents() Line 83	C++	Symbols loaded.
     	Qt5Cored.dll!qt_internal_proc(HWND__ * hwnd, unsigned int message, unsigned __int64 wp, __int64 lp) Line 237	C++	Symbols loaded.
     	[External Code]		Annotated Frame
     	Qt5Cored.dll!QEventDispatcherWin32::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 628	C++	Symbols loaded.
     	qwindowsd.dll!QWindowsGuiEventDispatcher::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 74	C++	Symbols loaded.
     	Qt5Cored.dll!QEventLoop::processEvents(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 135	C++	Symbols loaded.
     	Qt5Cored.dll!QEventLoop::exec(QFlags<enum QEventLoop::ProcessEventsFlag> flags) Line 212	C++	Symbols loaded.
     	Qt5Cored.dll!QCoreApplication::exec() Line 1291	C++	Symbols loaded.
     	Qt5Guid.dll!QGuiApplication::exec() Line 1680	C++	Symbols loaded.
     	Qt5Widgetsd.dll!QApplication::exec() Line 2911	C++	Symbols loaded.
     	QtChartTest2.exe!main(int argc, char * * argv) Line 9	C++	Symbols loaded.
     	QtChartTest2.exe!WinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, char * __formal, int __formal) Line 104	C++	Symbols loaded.
     	[External Code]		Annotated Frame
    


  • can you post the content of QtChartTest2::weightsHist()? and maybe tell us which line is line 30



  • @VRonin
    Sorry yeah, I should have been more clear.
    WeightsHist is a method that is called by a button being clicked, that is meant to open a dialog with a hist chart. I was just testing the example from above out when I encountered the issue.

    void QtChartTest2::weightsHist()
    {
    QDialog *dialog = new QDialog(this);

    QLineSeries* series = new QLineSeries();
    series->append(0, 6);
    series->append(2, 4);
    
    QHBoxLayout *chartLayout = new QHBoxLayout;
    dialog->setLayout(chartLayout);
    
    QChart *chart = new QChart();
    chart->legend()->hide();
    chart->addSeries(series);
    chart->createDefaultAxes();
    chart->setTitle("Weights Histogram");
    
    QChartView *chartView = new QChartView(chart);
    chartView->setRenderHint(QPainter::Antialiasing);
    
    
    chartLayout->addWidget(chartView);
    
    dialog->exec();
    

    }

    Line 30 is QChart *chart = new QChart();



  • Strange... what version of Qt are you running? are you using the MSVC2017 compiler in Qt creator too?



  • @VRonin
    5.9.2. I was running 5.9.1 when I first encountered this, but updating changed nothing. And yeah, I am running the same compiler in qtcreator as well, I made sure of that.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.