Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Why doesn't the QQuickWidget program display when using QML Model?

Why doesn't the QQuickWidget program display when using QML Model?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 4 Posters 687 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.
  • M Offline
    M Offline
    mirro
    wrote on last edited by mirro
    #1

    QQuickWidget to replace the QQmlApplicationEngine in the example
    https://github.com/ColinDuquesnoy/QtQuickControls2.TreeView

       QQucikWidget* pWidget = new QQucikWidget();
       pWidget->setResizeMode(QuickWidget:SizeRootObjectToView);
     
        QStandardItemModel standardItemModel;
        QStandardItem root("Root");
        root.setIcon(qtApp.style()->standardIcon(QStyle::SP_DesktopIcon));
        QStandardItem child1("Child 1");
        QStandardItem child2("Child 2");
        QStandardItem child3("Child 3");
        QStandardItem child1OfChild1("Child 1 of Child 1");
        QStandardItem child2OfChild1("Child 2 of Child 1");
        QStandardItem child1OfChild2("Child 1 of Child 2");
    
        child1.appendRow(&child1OfChild1);
        child1.appendRow(&child2OfChild1);
        child2.appendRow(&child1OfChild2);
        root.appendRow(&child1);
        root.appendRow(&child2);
        root.appendRow(&child3);
        standardItemModel.appendRow(&root);
    
        TreeViewModel standardItemTreeViewModel;
        standardItemTreeViewModel.setSourceModel(&standardItemModel);
    
        pWidget ->rootContext()->setContextProperty("standardItemModel", &standardItemTreeViewModel);
    
         pWidget ->load(QUrl("qrc:/main.qml"));
         pWidget ->show()
    
    J.HilkJ 1 Reply Last reply
    0
    • M mirro

      QQuickWidget to replace the QQmlApplicationEngine in the example
      https://github.com/ColinDuquesnoy/QtQuickControls2.TreeView

         QQucikWidget* pWidget = new QQucikWidget();
         pWidget->setResizeMode(QuickWidget:SizeRootObjectToView);
       
          QStandardItemModel standardItemModel;
          QStandardItem root("Root");
          root.setIcon(qtApp.style()->standardIcon(QStyle::SP_DesktopIcon));
          QStandardItem child1("Child 1");
          QStandardItem child2("Child 2");
          QStandardItem child3("Child 3");
          QStandardItem child1OfChild1("Child 1 of Child 1");
          QStandardItem child2OfChild1("Child 2 of Child 1");
          QStandardItem child1OfChild2("Child 1 of Child 2");
      
          child1.appendRow(&child1OfChild1);
          child1.appendRow(&child2OfChild1);
          child2.appendRow(&child1OfChild2);
          root.appendRow(&child1);
          root.appendRow(&child2);
          root.appendRow(&child3);
          standardItemModel.appendRow(&root);
      
          TreeViewModel standardItemTreeViewModel;
          standardItemTreeViewModel.setSourceModel(&standardItemModel);
      
          pWidget ->rootContext()->setContextProperty("standardItemModel", &standardItemTreeViewModel);
      
           pWidget ->load(QUrl("qrc:/main.qml"));
           pWidget ->show()
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @mirro do you call show() on your pWidget?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      M 1 Reply Last reply
      0
      • J.HilkJ J.Hilk

        @mirro do you call show() on your pWidget?

        M Offline
        M Offline
        mirro
        wrote on last edited by mirro
        #3

        @J-Hilk

        QQuickWidget doesn't work with QML Model ?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Depending on where that code lives, your model and all its items will be destroyed before even being used.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          M 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            Depending on where that code lives, your model and all its items will be destroyed before even being used.

            M Offline
            M Offline
            mirro
            wrote on last edited by mirro
            #5

            @SGaist
            What should I do?Create in heap space?

            TreeViewModel* pStandardItemTreeViewModel  = new TreeViewModel();
            pStandardItemTreeViewModel ->setSourceModel(&standardItemModel);
            
            pWidget ->rootContext()->setContextProperty("standardItemModel", pStandardItemTreeViewModel  );
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You do not provide enough code to get a proper answer. There's not enough context.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              M 1 Reply Last reply
              0
              • SGaistS SGaist

                You do not provide enough code to get a proper answer. There's not enough context.

                M Offline
                M Offline
                mirro
                wrote on last edited by
                #7

                @SGaist

                I used QQuickWidget to replace the QQmlApplicationEngine in the follow example of this url.
                https://github.com/ColinDuquesnoy/QtQuickControls2.TreeView

                1 Reply Last reply
                0
                • eyllanescE Offline
                  eyllanescE Offline
                  eyllanesc
                  wrote on last edited by eyllanesc
                  #8

                  @mirro create QStandardItemModel standardItemModel and standardItemTreeViewModel in the heap. The explanation is simple: local variables are removed at the end of their scope and that is not what you want.

                  If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                  1 Reply Last reply
                  1

                  • Login

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