[solved] Emulator crashed during flick



  • Hi,

    the emulator crashes if an element from the list leaves the screen by flicking.

    • I would like to know if this a list is possible with this approach. It would be nice at least for prototyping.

    Feed dataHandler
    @
    DataHandler dataHandler(this);
    dataHandler.addDay(new Day(&dataHandler, "id1", "dispVal1"));
    dataHandler.addDay(new Day(&dataHandler, "id2", "dispVal2"));
    dataHandler.addDay(new Day(&dataHandler, "id3", "dispVal3"));
    m_context->setContextProperty("dataHandler", &dataHandler);
    @

    DataHandler
    @
    class DataHandler : public QObject
    {
    Q_OBJECT

    Q_PROPERTY(QString version READ getVersion)
    Q_PROPERTY(QList<QObject *> days READ getDays)
    

    public:
    DataHandler(QObject *parent = 0);
    ~DataHandler();

    QString getVersion() { return m_version; }
    
    QList<QObject *> getDays(){ return m_days; }
    void addDay(QObject *day){ m_days.append(day); }
    

    private:
    QString m_version;
    QList<QObject *> m_days;
    };
    @

    Day
    @
    class Day : public QObject
    {
    Q_OBJECT

    Q_PROPERTY(QString dayId READ getDayId)
    Q_PROPERTY(QString dayDispValue READ getDayDispValue)
    

    public:
    Day(QObject *parent, const QString &dayId, const QString &dayDispValue);
    ~Day();

    QString getDayId() { return m_dayId; }
    QString getDayDispValue() { return m_dayDispValue; }
    

    private:
    QString m_dayId;
    QString m_dayDispValue;

    };
    @

    EDIT: QML
    @
    import QtQuick 1.0 // to target S60 5th Edition or Maemo 5

    Rectangle {
    width: 360
    height: 360
    Text {
    text: qsTr("Version: " + dataHandler.version)
    anchors.centerIn: parent
    }

    ListView{
        anchors.fill: parent
        model: dataHandler.days
        spacing: 5
    
        delegate: Rectangle{
    
            property string dispVal: modelData.dayDispValue
    
            color: "red"
            width: parent.width
            height: 30
            Text{
                text: "DisplVal: " + dispVal
            }
        }
    }
    

    }
    @

    • QAbsractItemList works for simple lists. But I would like to make a TreeView (port a app from PySide) and this approach would be the easiest if it would work :).

    Thank you.



  • One first thought that i would have is that happens because almost anything that leaves the screen might get destroyed and re-created when irt gets back in the screen. So take a good look if anything in your code could be affected by this.

    In the meantime, "this is a good article":http://cdumez.blogspot.com/2010/11/how-to-use-c-list-model-in-qml.html to take a look at regarding the creation of list models from C++ and using them in QML



  • Hi,

    thats the point, why does it initially work but when it gets re-created it crashes. Im sadly not that deep in the "mechanics" of QML.

    Yeah, I know this article, this blog is quite awesome :).

    Solution:
    Sadly I will get back of using QAbstractListModel even if i dont need its features. For my initial Problem I also found a solution.
    Example: I used the QAbstractListModel to handle my Day(see above) objects.
    Each Day has now a QList<Bills *> of Bills(same structure as Day just with different attributes). The Role name for this QList is BillsRole. Its now has a 2 level tree structure.

    As the return type of "QVariant DayModel::data(const QModelIndex &index, int role) const" fits best with "QVariant::QVariant(QList<QVariant>)" I tried following:
    @
    if(role == BillsRole){
    QList<QVariant> variantList;
    foreach(QObject *bill, day->getBills()){
    variantList.append(qVariantFromValue(bill));
    }
    return QVariant::QVariant(variantList);
    }
    @

    ... hurra no crashes anymore. Seems to work now.

    Thanks again.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.