QAbstractListModel + SectionScroller =分段错误

时间:2013-03-26 16:41:35

标签: c++ qt list segmentation-fault qml

我正在使用QML SectionScroller来滚动QML ListView。当我经常使用SectionScroller时,我在

中遇到了分段错误
_ZN18QAbstractItemModel4sortEiNQt9SortOrder: ldrex r1, [r3]

一些重要的代码

IrregularListWrapper::IrregularListWrapper()
{
    QHash<int, QByteArray> roles;
    roles[Form0Role] = "form0";
    roles[Form1Role] = "form1";
    roles[Form2Role] = "form2";

    setRoleNames(roles);
    setLang(German);
}

QVariant IrregularListWrapper::data(const QModelIndex &index, int role) const
{
    if (!index.isValid()) return QVariant();
    const IrregularVerb* verb = db->at(index.row());
    switch (role)
    {
    case Form0Role:
        return verb->getForm0();
        break;
    case Form1Role:
        return verb->getForm1();
        break;
    case Form2Role:
        return verb->getForm2();
        break;
    }
    return QVariant();
}

void IrregularListWrapper::setLang(Language l)
{
    QPluginLoader loader(plugins[l]);
    db = qobject_cast<AbstractIrregularList*>(loader.instance());

    switch (l)
    {
    case English:
        langName = "English";
        break;
    case German:
        langName = "German";
        break;
    }
    emit langChanged();

}

为什么会导致分段错误?提前致谢。

/ edit:当正常滚动时,也存在分段错误,回溯是:

#0  QBasicAtomicInt::ref (this=0x18)
#1 QString (this=0xbe88d2a0, other=...)
#2 IrregularVerb::getForm2 (this=0x9e6de8)
#3 IrregularVerbWrapper::data(this=0x9e31b8, index=..., role=35) // the model
// some calls to libQtDeclarative

有什么问题? IrregularVerb类看起来像

class IrregularVerb : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString form0 READ getForm0 NOTIFY formChanged)
    Q_PROPERTY(QString form1 READ getForm1 NOTIFY formChanged)
    Q_PROPERTY(QString form2 READ getForm2 NOTIFY formChanged)
public:
    QString forms[3];
    QString getForm0() const { return forms[0]; }
    QString getForm1() const { return forms[1]; }
    QString getForm2() const { return forms[2]; }
    IrregularVerb(QString a, QString b, QString c) { forms[0] = a; forms[1] = b; forms[2] = c; }
signals:
    void formChanged();
};

由于

0 个答案:

没有答案