从stackview弹出时,带有c ++ nest listmodel的qml listview崩溃

时间:2016-02-24 03:04:52

标签: c++ ios listview qml nest

我有一个像这样的c ++ nest listmodel结构,

class ListModel : public AbstractListModel
{
    public:
    .....
    private:
        QList<QObject*> m_List;
}

class TrendListModel : public ListModel
{
public:
    .....
    void addTrendData(.....)
    {
        TrendData* trendData = new TrendData(....);

        QQmlEngine::setObjectOwnership(trendData, QQmlEngine::CppOwnership);

        beginInsertRows(QModelIndex(), rowCount(), rowCount());
        m_List << trendData;
        endInsertRows();
    }

    void addImage(int row, QString path)
    {
        if(row < 0 || row >= rowCount())
        {
            qWarning() << "addImage to invalid trendData pointer!"
            return;
        }
        TrendData* trendData = qobject_cast<TrendData*>(m_List.at(row));
        trendData->addImage(...., path);

        emit dataChanged(index(row), index(row));
    }
}

class TrendData : public QObject 
{
  public:
     .....
     {
         m_ImageListModel = new ImageListModel(this);
         QQmlEngine::setObjectOwnership(m_ImageListModel, QQmlEngine::CppOwnership);
     }
     void addImage(..., path)
     {
        m_ImageListModel->addImage(..., path);
     }
  private:
      ImageListModel* m_ImageListModel;    
}

class ImageListModel : public ListModel
{
    void addImage(..., path)
     {
         Image* image = new Image(path, this);

         QQmlEngine::setObjectOwnership(image, QQmlEngine::CppOwnership);
         beginInsertRows(QModelIndex(), rowCount(), rowCount());
         m_List << image;
         endInsertRows();
     }
}

ListView{
    model: trendListModel //from setContextProperty()

    delegate{
        .......
        ListView{
            model: imageListModel //return from trendListModel's data function
        }
    }
}

我将TrendListModel的实例附加到qml listview,正确预览,但是当我从stackview弹出qml页面时,它在ios上崩溃,但在android上工作正常。如下所示,附上崩溃报告:

crash screenshot

0 个答案:

没有答案