QFileSystemModel QML type crashes upon MultiSelection when mouse pointer moves beyond row 0



  • Hi
    The following miminal example, basically a stripped-down version of
    https://doc.qt.io/qt-5.11/qtquickcontrols-filesystembrowser-example.html
    crashes when in a multi selection mode (e.g. SelectionMode.MultiSelection or SelectionMode.ExtendedSelection), the selection mouse pointer is dragged beyond row 0.

    filesystembrowser.pro:

    TEMPLATE = app
    TARGET = filesystembrowser
    QT += qml quick widgets
    
    SOURCES += main.cpp
    
    RESOURCES += qml.qrc
    CONFIG += c++11
    
    INSTALLS += target
    

    main.cpp:

    #include <QApplication>
    #include <QQmlApplicationEngine>
    #include <QtQml>
    #include <QFileSystemModel>
    
    class DisplayFileSystemModel : public QFileSystemModel {
        Q_OBJECT
    public:
        explicit DisplayFileSystemModel(QObject *parent = nullptr)
            : QFileSystemModel(parent) {}
    
        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
        {
            return QFileSystemModel::data(index, role);
        }
    
        QHash<int,QByteArray> roleNames() const override
        {
             QHash<int, QByteArray> result = QFileSystemModel::roleNames();
             return result;
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication app(argc, argv);
    
        QQmlApplicationEngine engine;
        qmlRegisterUncreatableType<DisplayFileSystemModel>("io.qt.examples.quick.controls.filesystembrowser", 1, 0,
                                                           "FileSystemModel", "Cannot create a FileSystemModel instance.");
    
        QFileSystemModel *fsm = new DisplayFileSystemModel(&engine);
    
        fsm->setRootPath(QDir::homePath());
        fsm->setResolveSymlinks(true);
        engine.rootContext()->setContextProperty("fileSystemModel", fsm);
        engine.rootContext()->setContextProperty("rootPathIndex", fsm->index(fsm->rootPath()));
        engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
    
        if (engine.rootObjects().isEmpty())
            return -1;
    
        return app.exec();
    }
    
    #include "main.moc"
    

    main.qml:

    import QtQuick 2.11
    import QtQuick.Controls 1.4
    import QtQml.Models 2.11
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("File System")
    
        ItemSelectionModel {
            id: selectionModel
            model: fileSystemModel
        }
    
        TreeView {
            id: view
            anchors.fill: parent
            model: fileSystemModel
            rootIndex: rootPathIndex
    
            selection: selectionModel
            selectionMode: SelectionMode.MultiSelection //SelectionMode.ExtendedSelection
    
            TableViewColumn {
                title: "Name"
                role: "fileName"
                resizable: true
            }
        }
    }
    

    The debugger halts at:

    QPersistentModelIndex::operator const QModelIndex&() const
    {
        static const QModelIndex invalid;
        if (d)                                                         <-- DEBUGGER HALTS HERE
            return d->index;
        return invalid;
    }
    

    The stack backtrace is:

    1  QPersistentModelIndex::operator QModelIndex const& qabstractitemmodel.cpp           272  0x7ffff585d2e0 
    2  QQuickTreeModelAdaptor1::selectionForRowRange      qquicktreemodeladaptor.cpp       292  0x7fffd8cdd9b8 
    3  QQuickTreeModelAdaptor1::qt_static_metacall        moc_qquicktreemodeladaptor_p.cpp 212  0x7fffd8cf4ec8 
    4  QQuickTreeModelAdaptor1::qt_metacall               moc_qquicktreemodeladaptor_p.cpp 337  0x7fffd8cf56e8 
    5  QQmlObjectOrGadget::metacall                       qqmlpropertycache.cpp            1733 0x7ffff637d389 
    6  CallMethod                                         qv4qobjectwrapper.cpp            1175 0x7ffff62ead8d 
    7  CallPrecise                                        qv4qobjectwrapper.cpp            1437 0x7ffff62ec2dd 
    8  QV4::QObjectMethod::callInternal                   qv4qobjectwrapper.cpp            1975 0x7ffff62ed066 
    9  QV4::FunctionObject::call                          qv4functionobject_p.h            163  0x7ffff6307fb0 
    10 QV4::Runtime::method_callProperty                  qv4runtime.cpp                   1062 0x7ffff6307fb0 
    11 QV4::Moth::VME::exec                               qv4vme_moth.cpp                  800  0x7ffff62fad5a 
    12 QV4::FunctionObject::call                          qv4functionobject_p.h            163  0x7ffff6307fb0 
    13 QV4::Runtime::method_callProperty                  qv4runtime.cpp                   1062 0x7ffff6307fb0 
    14 QV4::Moth::VME::exec                               qv4vme_moth.cpp                  800  0x7ffff62fad5a 
    15 QV4::Moth::VME::exec                               qv4vme_moth_p.h                  72   0x7ffff63ac1d6 
    16 QV4::Function::call                                qv4function_p.h                  72   0x7ffff63ac1d6 
    17 QQmlJavaScriptExpression::evaluate                 qqmljavascriptexpression.cpp     217  0x7ffff63ac1d6 
    18 QQmlBoundSignalExpression::evaluate                qqmlboundsignal.cpp              237  0x7ffff6342269 
    19 QQmlBoundSignal_callback                           qqmlboundsignal.cpp              370  0x7ffff6343753 
    20 QQmlNotifier::emitNotify                           qqmlnotifier.cpp                 106  0x7ffff63875f4 
    21 QQmlData::signalEmitted                            qqmlengine.cpp                   861  0x7ffff6326194 
    22 QMetaObject::activate                              qobject.cpp                      3649 0x7ffff58d6e32 
    23 QMetaObject::activate                              qobject.cpp                      3633 0x7ffff58d70d7 
    24 QQmlTimer::triggered                               moc_qqmltimer_p.cpp              261  0x7ffff6413750 
    25 QQmlTimer::ticked                                  qqmltimer.cpp                    323  0x7ffff6413b7f 
    26 QQmlTimer::event                                   qqmltimer.cpp                    335  0x7ffff6413e4c 
    27 QApplicationPrivate::notify_helper                 qapplication.cpp                 3727 0x7ffff7083eac 
    28 QApplication::notify                               qapplication.cpp                 3486 0x7ffff708afe0 
    29 QCoreApplication::notifyInternal2                  qcoreapplication.cpp             1048 0x7ffff58ab918 
    30 QCoreApplication::sendEvent                        qcoreapplication.h               234  0x7ffff58ae32b 
    31 QCoreApplicationPrivate::sendPostedEvents          qcoreapplication.cpp             1745 0x7ffff58ae32b 
    32 QCoreApplication::sendPostedEvents                 qcoreapplication.cpp             1599 0x7ffff58ae818 
    33 postEventSourceDispatch                            qeventdispatcher_glib.cpp        276  0x7ffff59001c3 
    34 g_main_context_dispatch                                                                  0x7ffff18547f7 
    35 ??                                                                                       0x7ffff1854a60 
    36 g_main_context_iteration                                                                 0x7ffff1854b0c 
    37 QEventDispatcherGlib::processEvents                qeventdispatcher_glib.cpp        423  0x7ffff58ff81f 
    38 QPAEventDispatcherGlib::processEvents              qeventdispatcher_glib.cpp        69   0x7fffee875831 
    39 QEventLoop::exec                                   qeventloop.cpp                   214  0x7ffff58aa27a 
    40 QCoreApplication::exec                             qcoreapplication.cpp             1336 0x7ffff58b2c80 
    41 main                                               main.cpp                         43   0x5555555572f5 
    

    I tested this with Qt 5.11.1 and 5.11.2 on a Debian 9.5 VM and Qt 5.11.0 on Windows 10 x64. They all crash.

    Any ideas?
    Thanks!

    Edit: this is not specific to QFileSystemModel it seems. I have another QAbstractItemModel-derived model that also crashes in a similar fashion.


  • Lifetime Qt Champion

    Hi,

    It's a bug. You should check the bug report system to see if it's something known. If not, please consider opening a new report providing your complete example.




Log in to reply
 

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