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. How can i start a global qml viewer or a child Form of my app?
Forum Updated to NodeBB v4.3 + New Features

How can i start a global qml viewer or a child Form of my app?

Scheduled Pinned Locked Moved QML and Qt Quick
12 Posts 3 Posters 4.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.
  • M Offline
    M Offline
    MartinJ
    wrote on last edited by
    #2

    You created viewer2 on the stack. When the function exits it goes out of scope and is destroyed.

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hexenbrennen
      wrote on last edited by
      #3

      thx

      but how can i create a global viewer?

      or how can i start a child Form from a qml file?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #4

        Create viewer2 on the heap instead. Creating objects on the stack in the main() function is fine, but elsewhere usually not.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hexenbrennen
          wrote on last edited by
          #5

          now i have a memory leak after closing? there shoudnt be a problem with this or?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #6

            Well, either make sure you delete it yourself, or simply give it a sensible parent object to delete it for you.

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hexenbrennen
              wrote on last edited by
              #7

              thx

              when i call the viewer i exit the class and go to the app event loop.

              how can i delete this Viewer/Object when the destructor is called manually?

              the leak occurse after closing the app

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #8

                In order to delete an object manually (why do you insist on doing it manually?), you need to keep a pointer to the object around. So, make sure you get a pointer to it, and store it.

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  hexenbrennen
                  wrote on last edited by
                  #9

                  thx andre for your reply

                  but i dont get it.

                  when i have sth like this:

                  @Q_DECL_EXPORT int main(int argc, char *argv[])
                  {
                  QScopedPointer<QApplication> app(createApplication(argc, argv));

                  QmlApplicationViewer viewer;
                  viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
                  viewer.setMainQmlFile&#40;QLatin1String("qml/testleak/main.qml"&#41;&#41;;
                  viewer.showExpanded();    
                  
                  QmlApplicationViewer viewer1;
                  viewer1.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
                  viewer1.setMainQmlFile&#40;QLatin1String("qml/testleak/main.qml"&#41;&#41;;
                  viewer1.showExpanded();
                  
                  
                  return app->exec(&#41;;
                  

                  }@

                  how can i realize this command viewer.hide

                  after i started the qml app

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #10

                    There is no memory leak in the code you just posted, though I can't judge what happens in createApplication() of course.

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      hexenbrennen
                      wrote on last edited by
                      #11

                      this produces the leak "view" gets never deleted

                      but more important would be how can I create more viewer after the app has started

                      @void init(QString qmlfile)
                      {
                      QmlApplicationViewer *view = new QmlApplicationViewer;
                      view->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
                      view->setSource(QUrl(qmlfile));
                      view->showExpanded();
                      return;
                      }

                      Q_DECL_EXPORT int main(int argc, char *argv[])
                      {
                      QScopedPointer<QApplication> app(createApplication(argc, argv));

                      init("qml/testleak/main.qml");
                      
                      QmlApplicationViewer viewer;
                      viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
                      viewer.setMainQmlFile&#40;QLatin1String("qml/testleak/main.qml"&#41;&#41;;
                      viewer.showExpanded();
                      viewer.show();
                      
                      QmlApplicationViewer viewer1;
                      viewer1.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
                      viewer1.setMainQmlFile&#40;QLatin1String("qml/testleak/main.qml"&#41;&#41;;
                      viewer1.showExpanded();
                      
                      
                      return app->exec(&#41;;
                      

                      }@

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #12

                        Keep the pointer to the QmlQpplicationViewer object somewhere. At the moment, you just let it go out of scope.

                        On the other hand, you could also just set the WA_DeleteOnClose flag on the widget.

                        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