访问类成员会创建访问冲突

时间:2016-10-15 05:38:46

标签: c++ qt

我有一个QT cpp类定义如下:

class signalTapSignalAggregator : public  QAbstractTableModel
{
public:
    signalTapSignalAggregator();
    void addSignalTapSignal(signalTapSignal &signalTapSignalInst);
    int rowCount(const QModelIndex & parent = QModelIndex()) const;
    int columnCount(const QModelIndex & parent = QModelIndex()) const;
    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
    int numberOfRow;
private:
    QVector<signalTapSignal> listOfSignals;

};



signalTapSignalAggregator::signalTapSignalAggregator()
{
numberOfRow = 0;
}

void signalTapSignalAggregator::addSignalTapSignal(signalTapSignal &signalTapSignalInst){
int sizeOfSignal = signalTapSignalInst.getSignalLength();
if(sizeOfSignal >= 0){
    try{
        numberOfRow= signalTapSignalInst.getSignalLength();
    }catch(std::exception& e)
    {
        qDebug() << "Caught Exception" ;

    }
}
listOfSignals.push_back(signalTapSignalInst);
}

int signalTapSignalAggregator::rowCount(const QModelIndex & parent) const{
return numberOfRow;
}

 int signalTapSignalAggregator::columnCount(const QModelIndex & parent) const{
return listOfSignals.size();
 }

QVariant signalTapSignalAggregator::data(const QModelIndex & index, int role) const{
QString fieldName;

switch(role){
    case Qt::DisplayRole:

        fieldName = listOfSignals.at(index.column()).feildName;

        break;
    case Qt::DecorationRole:
        break;
    case Qt::EditRole:
        break;
    case Qt::ToolTipRole:
        break;
    case Qt::StatusTipRole:
        break;
    case Qt::WhatsThisRole:
        break;
    case Qt::SizeHintRole:
        break;
}

return fieldName;
}

当我尝试在函数addSignalTapSignal()中设置成员变量numberOfRow时,函数addSignalTapSignal正在调用访问冲突

我收到的错误消息是:

  

下级因为触发异常而停止了

     

在线程0中停止:异常为0x7ff6c2a586ac,代码0xC0000005:在0x1写入访问冲突,标志= 0x0。

从我的角度来看,我正在尝试写入类signalTapSignalAggregator中的成员变量

我不知道我做错了什么......

我怀疑类signalTapSignalAggregator的实例尚未正确初始化...

signalTapSignalAggregator *signalTapSignalAggregatorInst = new signalTapSignalAggregator();
signalTapParser *signalTapParserInst = new signalTapParser(signalTapSignalAggregatorInst);

类signalTapParser对signalTapSignalAggregator有参考,它调用方法addSignalTapSignal(),当调用函数addSignalTapSignal()时发生访问冲突...

0 个答案:

没有答案