QChart中QScatterSeries的点击信号触发后,执行槽函数后出现空指针异常,异常位置在源码scatterchartitem类中的setMousePressed()方法



  • 0_1521180586786_捕获.PNG



  • 信号与槽的连接

    for(int i = 0; i < charts_list_->count(); i++){
            connect(charts_list_->at(i)->series2_,SIGNAL(clicked(QPointF)),this,SLOT(series2HandleClickedPoint(QPointF)));
    }
    

    槽函数

    void View::series2HandleClickedPoint(const QPointF &point){
        PulseGraphOperator::UnSelectPointInAllCharts(charts_list_, point.x());
    }
    

    UnSelectPointInAllCharts()方法是为了多个图同步进行反选

    void PulseGraphOperator::UnSelectPointInAllCharts(QList<Chart *> *list, qreal xpos){
        for(int i = 0; i < list->count(); i++){
            PulseGraphOperator::UnSelectPoint(list->at(i), xpos);
        }
    }
    

    UnSelectPoint()方法实现反选,将反选的点从已选中序列series2中移除,添加到原序列series1

    void PulseGraphOperator::UnSelectPoint(Chart* chart, qreal xpos){
        QPointF clicked_point;
        if(chart->series2_->points().size() > 1){
            foreach(QPointF series2_point, chart->series2_->points()){
                if(series2_point.x() == xpos){
                    clicked_point = series2_point;
                    break;
                }
            }
            chart->series1_->append(clicked_point);
            chart->series2_->remove(clicked_point);
            qDebug()<<"series2.point > 1";
        }else{
            chart->series1_->append(chart->series2_->points());
            chart->series2_->clear();
            qDebug()<<"series2.point = 1";
        }
        qDebug()<<"UnSelect point";
    }
    

    无奈出现空指针异常,读取或者访问冲突,不知道问题出在哪里?


Log in to reply
 

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