Discussion Board

Results 1 to 2 of 2
  1. #1
    Nokia Developer Expert
    Join Date
    Jul 2011

    Opening multiple QML pages from Cpp?


    I am building an application which utilizes several distinct QML UI pages that are loaded from C++ code. Now it seems that even if I manage to open the pages relatively easily, the solution I have built causes the application to crash in mobile device (N8) after several (tens of) page loads.

    It seems that bigger the QML page content, the faster the app crashes. Thus I suspect that my page loading leaks resources.

    Here is the page loading code. Any idea what is wrong?

        In header:
        QGraphicsScene *scene;
        QGraphicsView *view;
        QDeclarativeEngine *engine;
        QDeclarativeContext *context;
        QDeclarativeComponent *component;
        QDeclarativeItem *item;
        QDesktopWidget *myScreen;
        QRect ScreenDim;
    QmlCppMediator::QmlCppMediator(QObject *parent) :
        scene = new QGraphicsScene;
        view = new QGraphicsView(scene);
        engine = new QDeclarativeEngine();
        context = engine->rootContext();
    Q_INVOKABLE void QmlCppMediator::changeQMLSource(QString page) {
        if (component){
            delete component;
        ScreenDim = myScreen->screenGeometry();
        int width = ScreenDim.width();
        int height = ScreenDim.height();
        scene->setSceneRect (0,0,width,height);
        component = new QDeclarativeComponent (engine, QUrl::fromLocalFile(page));
        item = qobject_cast<QDeclarativeItem *>(component->create());
    br, _perza

  2. #2
    Super Contributor
    Join Date
    Mar 2009

    Re: Opening multiple QML pages from Cpp?

    I suspect it crashes when you call "delete component".
    In general delete a QObject instance leads to crashes.
    So, since QDeclarativeItem is a QObject I suggest you to use QObject::deleteLater() instead.

    Other tips:
    - Change changeQMLSource(QString page) to changeQMLSource(const QString& page)
    - all objects are created on the heap and they don't have parent, I hope you delete them in the class destructor!
    - Is engine object useful? IIRC the view should instantiate one for you

Similar Threads

  1. Multiple pages in QStackedWidget
    By yannifan in forum Qt
    Replies: 3
    Last Post: 2011-03-14, 14:55
  2. Anybody knows when will nokia 5800 get new homescreen with multiple pages
    By ramesh5180 in forum General Development Questions
    Replies: 4
    Last Post: 2010-05-12, 19:10
  3. Soft keys for multiple pages
    By nithyas in forum [Archived] Flash Lite on Nokia Devices
    Replies: 1
    Last Post: 2008-08-08, 13:12
  4. Problem of multiple pages
    By chheang in forum Symbian
    Replies: 1
    Last Post: 2002-09-04, 07:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts