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. QQmlApplicationEngine not completely unloading qml components

QQmlApplicationEngine not completely unloading qml components

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 941 Views
  • 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.
  • D Offline
    D Offline
    developa
    wrote on last edited by developa
    #1

    I'm currently loading my main.qml using QQmlApplicationEngine and works fine, and then I want to switch to main2.qml (without calling quit() on my QQmlApplicationEngine since that triggers QCoreApplication::exit() which will exit my application). So I just delete my engine, make a new one and set the context properties again (not the same context properties for main.qml slightly different), and it loads fine. But I get warnings like

    qrc:/qml/...: Unable to assign [undefined] to bool
    

    Why is the engine not unloading and reloading the qml files again? Why do I get a warning for a property that was defined when I loaded the engine the first time but isn't defined when I load the second time.

    NOTE: If I load main2.qml first, I don't get the warning, even though the property is undefined.

    Your help is appreciated.

    EDIT: Here is my code

    QSharedPointer<QQmlApplicationEngine> m_engine;
    QQmlContext* m_ctxt;
    
    void loadEngine(int window){
        m_engine->clearComponentCache();
        m_engine.reset(new QQmlApplicationEngine, &QObject::deleteLater);
        m_ctxt = m_engine->rootContext();
    
        m_ctxt->setParent(m_engine.get());
        QVector<QQmlContext::PropertyPair> qmlProperties;
    
        qmlProperties.push_back(QQmlContext::PropertyPair{"object", QVariant::fromValue(object)});
    
        if(window == 1){
            qmlProperties.push_back(QQmlContext::PropertyPair{"object1", QVariant::fromValue(object1)});
            // add more context properties
    
            m_ctxt->setContextProperties(qmlProperties);
            m_engine->load(QUrl(QLatin1String("qrc:/qml/main.qml")));
        }
        else{    
            qmlProperties.push_back(QQmlContext::PropertyPair{"object2", QVariant::fromValue(object2)});
            // add more context properties
    
            m_ctxt->setContextProperties(qmlProperties);
            m_engine->load(QUrl(QLatin1String("qrc:/qml/main2.qml")));
        }
    }
    
    M 1 Reply Last reply
    0
    • D developa

      I'm currently loading my main.qml using QQmlApplicationEngine and works fine, and then I want to switch to main2.qml (without calling quit() on my QQmlApplicationEngine since that triggers QCoreApplication::exit() which will exit my application). So I just delete my engine, make a new one and set the context properties again (not the same context properties for main.qml slightly different), and it loads fine. But I get warnings like

      qrc:/qml/...: Unable to assign [undefined] to bool
      

      Why is the engine not unloading and reloading the qml files again? Why do I get a warning for a property that was defined when I loaded the engine the first time but isn't defined when I load the second time.

      NOTE: If I load main2.qml first, I don't get the warning, even though the property is undefined.

      Your help is appreciated.

      EDIT: Here is my code

      QSharedPointer<QQmlApplicationEngine> m_engine;
      QQmlContext* m_ctxt;
      
      void loadEngine(int window){
          m_engine->clearComponentCache();
          m_engine.reset(new QQmlApplicationEngine, &QObject::deleteLater);
          m_ctxt = m_engine->rootContext();
      
          m_ctxt->setParent(m_engine.get());
          QVector<QQmlContext::PropertyPair> qmlProperties;
      
          qmlProperties.push_back(QQmlContext::PropertyPair{"object", QVariant::fromValue(object)});
      
          if(window == 1){
              qmlProperties.push_back(QQmlContext::PropertyPair{"object1", QVariant::fromValue(object1)});
              // add more context properties
      
              m_ctxt->setContextProperties(qmlProperties);
              m_engine->load(QUrl(QLatin1String("qrc:/qml/main.qml")));
          }
          else{    
              qmlProperties.push_back(QQmlContext::PropertyPair{"object2", QVariant::fromValue(object2)});
              // add more context properties
      
              m_ctxt->setContextProperties(qmlProperties);
              m_engine->load(QUrl(QLatin1String("qrc:/qml/main2.qml")));
          }
      }
      
      M Offline
      M Offline
      Mammamia
      wrote on last edited by Mammamia
      #2

      @developa said in QQmlApplicationEngine not completely unloading qml components:

      void loadEngine(int window){
      m_engine->clearComponentCache();

      IIRC you should also call trimComponentCache https://doc.qt.io/qt-5/qqmlengine.html#trimComponentCache

      void loadEngine(int window){
          m_engine->clearComponentCache();
          m_engine->trimComponentCache();
      
      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