mardi 28 juin 2016

Segmentation Fault when using some Qt5 classes in a QtQuick 2 application

When trying to use some Qt-5 classes I'm experiencing crashes. I first discovered this trying to use QFileSystemModel. Trying to call setRootPath immediately leads to a crash. The callstack isn't of much help (all of it is assembly code) except that QFileIconProvider::icon() is the last function called before the seg fault occurs.

So next I tried using QFileIconProvider manually and -to no surprise- it also crashed the program.

I'm using QtCreator 4 and the type of project is "Qt Quick Application". When I instead create a project of type "Qt Widgets Application", I can use both QFileIconProvider and QFileSystemModel without problems.

Here's where I'm out of ideas. I don't know enough about the Qt environment to know what difference between the two types of projects could lead to the seg fault.

Both projects use the same Kit (same gcc, same Qt 5.6.1) and the default settings as set by QtCreator.

This is my project.pro file:

TEMPLATE = app

QT += qml quick widgets //default .pro file except for widgets
CONFIG += c++11

SOURCES += main.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Default rules for deployment.
include(deployment.pri)

This is main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

#include <QDir>
#include <QFileSystemModel>
#include <QQmlContext>
#include <QFileIconProvider>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    //If trying to use QFileSystemMode...
    QFileSystemModel model;
    model.setRootPath("/somefolder/"); //..the crash happens here

    //Attempting to use QFileIconProvider also crashes
    //QFileIconProvider fip;
    //fip.icon( QFileInfo("/somefolder/somefile") ); //<- here

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    return app.exec();
}

I'd appreciate any help or pointers as to how to debug that mess.

Aucun commentaire:

Enregistrer un commentaire