Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

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

    QML and Qt Quick
    3
    12
    3664
    Loading More Posts
    • 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.
    • H
      hexenbrennen last edited by

      Hi

      "Picture":http://www.imgbox.de/show/img/0hG7WzqFOI.jpg

      1 and 2 work but 3 doesnt work!
      There are no exception and the window gets created for a short moment but than crashes.

      i hope you can help me

      Ciao

      1 Reply Last reply Reply Quote 0
      • M
        MartinJ last edited by

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

        1 Reply Last reply Reply Quote 0
        • H
          hexenbrennen last edited by

          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 Reply Quote 0
          • A
            andre last edited by

            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 Reply Quote 0
            • H
              hexenbrennen last edited by

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

              1 Reply Last reply Reply Quote 0
              • A
                andre last edited by

                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 Reply Quote 0
                • H
                  hexenbrennen last edited by

                  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 Reply Quote 0
                  • A
                    andre last edited by

                    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 Reply Quote 0
                    • H
                      hexenbrennen last edited by

                      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 Reply Quote 0
                      • A
                        andre last edited by

                        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 Reply Quote 0
                        • H
                          hexenbrennen last edited by

                          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 Reply Quote 0
                          • A
                            andre last edited by

                            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 Reply Quote 0
                            • First post
                              Last post