3

我正在使用ListView带有SectionScroller&的 QML QAbstractListModel。我注意到memcpy当我正常滚动(不使用 )时(从未显式调用)出现SectionScroller分段错误

你知道为什么会这样吗?

我试图重现它,现在分段错误是

0x402f9c3a 在?? () 来自 /usr/lib/libQtScript.so.4
0x402f9c3a: ldrh r1, [r7, r3]

调试符号在那里,但没有有价值的信息被转储。另一次Segfault是

0x0000cab8 在 QBasicAtomicInt::ref (this=0x0) at /usr/include/QtCore/qatomic_armv6.h: 119

这很奇怪,因为 AFAIK N900 的处理器是 armv7 /edit:在 N950 上它使用相同的处理器,而 Qt 中的源代码仅适用于 ARM qatomic_arm.hqatomic_armv6.h所以应该没问题。

ListView{
    id: irrview
    width: parent.width
    model: irregulars
    anchors.top: caption.bottom
    anchors.bottom: parent.bottom
    spacing: 5
    clip: true
    section.criteria: ViewSection.FirstCharacter
    section.property: "form0"

    delegate: Rectangle{
        id: del
        property  int fontSize: 20
        height: 60
        width: parent.width
        color: "#E0E1E2"
        Row{
            height: parent.height
            width: parent.width - 10
            anchors.horizontalCenter: parent.horizontalCenter
            property real columnWidth: (width - 10) / 3
            property int rad: 10
            spacing: 5
            Rectangle{
                height: parent.height
                width: parent.columnWidth
                radius: parent.rad
                color: "lightsteelblue"
                Text{
                    anchors.centerIn: parent
                    text: form0
                    font.pointSize: del.fontSize
                }
            }
            Rectangle{
                height: parent.height
                width: parent.columnWidth
                radius: parent.rad
                color: "lightsteelblue"
                Text{
                    anchors.centerIn: parent
                    text: form1
                    font.pointSize: del.fontSize
                }
            }
            Rectangle{
                height: parent.height
                width: parent.columnWidth
                radius: parent.rad
                color: "lightsteelblue"
                Text{
                    anchors.centerIn: parent
                    text: form2
                    font.pointSize: del.fontSize
                }
            }
        }
    }
}

型号为:

#ifndef IRREGULARLISTWRAPPER_H
#define IRREGULARLISTWRAPPER_H

#include <QObject>
#include <QList>
#include <QAbstractListModel>
#include <QMap>
#include "IrregularVerb.h"
#include "AbstractIrregularList.h"

class IrregularListWrapper : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(QString langName READ getLangName NOTIFY langChanged)
    Q_PROPERTY(int count READ rowCount NOTIFY langChanged)
    Q_ENUMS(Language)
public:

    Q_INVOKABLE int rowCount(const QModelIndex& = QModelIndex()) const { return db->count(); }
    Q_INVOKABLE QObject* get(int index) const {return db->at(index);}
    QVariant data(const QModelIndex &index, int role) const;

    enum Language
    {
        English = 0,
        German = 1
    };

    enum IrregularVerbRoles
    {
        Form0Role = Qt::UserRole + 1,
        Form1Role,
        Form2Role
    };

    IrregularListWrapper();

//    ~IrregularListWrapper() { delete db; }
//    QList<QObject*> getdb() const { return *db; }

    QString getLangName() const { return langName; }
    Q_INVOKABLE void changeLang(Language l) { beginResetModel(); db = 0; /*QList<IrregularVerb*>();*/ setLang(l); endResetModel(); }

    static QMap<Language, QString> plugins;

signals:
    void langChanged();
protected:
    void setLang(Language);
    //QList<IrregularVerb*> db;
    QString langName;
    AbstractIrregularList * db;

};

#endif // IRREGULARLISTWRAPPER_H


QMap<IrregularListWrapper::Language, QString> IrregularListWrapper::plugins;

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

    const QString pluginPath = "/opt/MeeIrregulars/share/lib%1.so";

    plugins[English] = pluginPath.arg("english");
    plugins[German] = pluginPath.arg("german");

    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());

    if (db == 0) db = new AbstractIrregularList;

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

}


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 QBasicAtomicInt::ref (this=0x18)
#1 QString (this=0xbe88d2a0, other=...)
#2 IrregularVerb::getForm2 (this=0x9e6de8)
#3 IrregularVerbWrapper::data(this=0x9e31b8, index=. .., role=35)
// 模型
// 一些对 libQtDeclarative 的调用

谢谢。

4

1 回答 1

1

这是所有权的问题。返回的元素get归JS所有,自动销毁。有关更多信息,请参阅此答案

于 2015-07-31T07:06:48.317 回答