Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem in QCustomPlot class



  • hai I am using QCustomPlot in one of my application.

    while adding graph application is unexcpectedly closed

    in my mainwindow.cpp

    m_pCustomPlot->addGraph();(M_pCustomPlot is QCustomPlot*)

    @
    QCPGraph *QCustomPlot::addGraph(QCPAxis *keyAxis, QCPAxis *valueAxis)
    {
    if (!keyAxis) keyAxis = xAxis;
    if (!valueAxis) valueAxis = yAxis;
    if (!keyAxis || !valueAxis)
    {
    qDebug() << Q_FUNC_INFO << "can't use default QCustomPlot xAxis or yAxis, because at least one is invalid (has been deleted)";
    return 0;
    }
    if (keyAxis->parentPlot() != this || valueAxis->parentPlot() != this)
    {
    qDebug() << Q_FUNC_INFO << "passed keyAxis or valueAxis doesn't have this QCustomPlot as parent";
    return 0;
    }
    @

    in above code while assigning xAxis to keyAxis The program has unexpectedly finished.

    and

    ploting initialisation is as shown below
    @
    m_pCustomPlot->setWindowFlags(Qt::FramelessWindowHint);

    m_pCustomPlot->setMinimumSize(210,240);
    m_pCustomPlot->setGeometry(0,70,240,240);
    m_pCustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables);
    
    QFont legendFont = font();
    legendFont.setPointSize(8);
    

    m_pCustomPlot->xAxis->setRange(0,16384);
    m_pCustomPlot->yAxis->setRange(0,20000);
    m_pCustomPlot->axisRect()->setupFullAxesBox();

    m_pCustomPlot->plotLayout()->insertRow(0);
    
    m_pCustomPlot->xAxis->setLabel("Bin");
    m_pCustomPlot->xAxis->setLabelFont(legendFont);
    m_pCustomPlot->yAxis->setLabelFont(legendFont);
    m_pCustomPlot->yAxis->setLabel("Bin Count");
    

    @

    can any one please suggest me where I did mistake?

    Thanks in advance


  • Lifetime Qt Champion

    Hi,

    Did you correctly initialize (as in allocate) m_pCustomPlot ?



  • yes I did.
    @
    m_pCustomPlot = NULL;
    if(m_pCustomPlot == NULL){
    m_pCustomPlot = new QCustomPlot();
    m_pCustomPlot->setGeometry(0,0,120,80);
    m_pCustomPlot->resize(120,80);
    }
    @


  • Lifetime Qt Champion

    Then, run your program using the debugger, it will give you more information about what happens when it crashes



  • My project was in Debug mode but it's not giving any information.

    I have one more doubt, Can I use QCustomPlot to plot the graph continuously means can i update the garph for evry one sec.


  • Lifetime Qt Champion

    For such specialized question, you should contact the author of the library directly


Log in to reply