Qt World Summit: Register Today!

QT5 qml-components

  • Hi
    I-m trying to get to work a really simple app that uses qml-components, but I got an error.
    I use the latest QtCreator 2.6.1 and QT5.0
    Here is the code
    @int main(int argc, char *argv[])
    QGuiApplication app(argc, argv);

    QtQuick2ApplicationViewer viewer;

    return app.exec();


    And qml/temp/main.qml
    @import QtQuick 2.0
    import QtDesktop 1.0

    Rectangle {
    width: 360
    height: 360

    anchors.centerIn: parent

    And I get segmentation fault in QStyleItem::sizeFromContents
    I think this line inside QStyleItem::sizeFromContents fails
    qApp->style()->sizeFromContents(QStyle::CT_CheckBox, m_styleoption, QSize(width,height));
    where qApp is
    #define qApp (static_cast<QApplication *>(QCoreApplication::instance()))
    And it fails because qApp->style() return null.
    I tried to get style in main function
    auto papp = static_cast<QApplication *>(QCoreApplication::instance());
    auto style = papp->style();
    And indeed I got null

    Do you know how to fix it? Earlier I didn't have to set styles to work with qml-components

  • There is a dependency on widgets due to use of QWidget styles. The easiest fix is to make your QtGuiApplication into a QApplication. Alternatively you can create your own style and set it on the application. Then everything should work. We are working on making components not depend on widgets, but in that case you would not get the native look and feel. There clearly needs to be some documentation about this.

  • Oh! It works!
    I just replaced QGuiApplication with QApplication and now it works!
    Thanks a lot

  • Great. I pushed a small fix https://codereview.qt-project.org/#change,43595 so that people will get notified when this problem arises.

Log in to reply