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



  • 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



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



  • thx

    but how can i create a global viewer?

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



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



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



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



  • 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



  • 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.



  • 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



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



  • 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;;
    

    }@



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.