Important: Please read the Qt Code of Conduct -

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

    class DataHandler : public QObject

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

    DataHandler(QObject *parent = 0);

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

    QString m_version;
    QList<QObject *> m_days;

    class Day : public QObject

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

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

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

    QString m_dayId;
    QString m_dayDispValue;


    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

        anchors.fill: parent
        model: dataHandler.days
        spacing: 5
        delegate: Rectangle{
            property string dispVal: modelData.dayDispValue
            color: "red"
            width: parent.width
            height: 30
                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": 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 :).

    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()){
    return QVariant::QVariant(variantList);

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

    Thanks again.

Log in to reply