QQmlComponent load too slow at the first time???



  • Hello,
    I have to create many views and show it at runtime. My code is shown as below :

    void MyClass::MyClass(QQuickItem *viewContainer) : m_viewContainer(viewContainer)
    {
        m_view = nullptr;
    }
    void MyClass::changeView(QString url)
    {
         QUrl newUrl(url);
         QQmlComponent _component(MyApp::getInstance()->getQMLEngine(), newUrl);
         m_view = qobject_cast<QQuickItem *>(_component.create());
         if (m_view) {
            m_view->setParentItem(m_viewContainer);
        }
    }
    

    The problem occurs when I run changeView function with url parameter is passed for the first time , the new view is delayed about 3 seconds before display. Since the same url parameter is passed again (after change some others view), the view display normally.
    I don't know exactly the root cause of this issue. But I when I try to modify source code as below then issue is fixed :

    void MyClass::MyClass(QQuickItem *viewContainer) : m_viewContainer(viewContainer)
    {
        m_view = nullptr;
        foreach(QUrl currUrl, m_urlList)
             QQmlComponent _component(MyApp::getInstance()->getQMLEngine(), currUrl);
    }
    void MyClass::changeView(QString url)
    {
         QUrl newUrl(url); 
         QQmlComponent _component(MyApp::getInstance()->getQMLEngine(), newUrl);
         m_view = qobject_cast<QQuickItem *>(_component.create());
         if (m_view) {
            m_view->setParentItem(m_viewContainer);
        }
    }
    

    Could someone please help me explain this issue and suggest me the best way the fix this?
    Thank you very much.



  • Anyone there? Please help me for this issue? In QT document :
    "QQmlComponent::QQmlComponent(QQmlEngine * engine, const QUrl & url, QObject * parent = 0)
    Create a QQmlComponent from the given url and give it the specified parent and engine."
    I dont know what will happen after given url and engine to QQmlComponent but It seems load too slow if url is given at the first time?
    Could you please help me resolve this issue?
    Thank you.



  • Hello??? Can someone help me please???


Log in to reply
 

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