Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT5 qml-components
Forum Updated to NodeBB v4.3 + New Features

QT5 qml-components

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ittennull
    wrote on last edited by
    #1

    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;
    viewer.setMainQmlFile(QStringLiteral("qml/temp/main.qml"));
    viewer.showExpanded();

    return app.exec();
    

    }@

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

    Rectangle {
    width: 360
    height: 360

    CheckBox{
    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

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jens
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ittennull
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jens
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved