我正在使用 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();
};
谢谢