QQuickView hangs on delayed "setSource"



  • Hi all. I have an odd problem. I have a QQuickView object in my class A:

    class A : pubic QObject
    {
        Q_OBJECT
        ...
        ...
    
    private:
        QQuickView *m_quickView;
    }
    

    When i load the qml source file during the construction of the quickview

    A::A(QObject *parent)
        : QObject(parent)
        , m_quickView(new QQuickView(QUrl("qrc:/qml/default/main.qml")))
    {
    }
    

    all is well. If, instead, i delay the loading of the qml file, my quickview gets stuck in a LOADING state.

    A::A(QObject *parent)
        : QObject(parent)
        , m_quickView(new QQuickView)
    {
       projectToScreen(QUrl("qrc:/qml/default/main.qml"));
    }
    
    
    void A::projectToScreen(const QUrl &sourceUrl)
    {
        m_quickView->setSource(sourceUrl);
    }
    

    Any insight on why this is happening?


  • Moderators

    @nwoki
    i guess this is a stripped down version of your code right?
    I think the mistake is hidden somewhere in the code you haven't posted.



  • @raven-worx said in QQuickView hangs on delayed "setSource":

    @nwoki
    i guess this is a stripped down version of your code right?
    I think the mistake is hidden somewhere in the code you haven't posted.

    Full code doesn't differ that much from the stripped down version. Anyway, below you'll find the full code

    Core::Core(QObject *parent)
        : QObject(parent)
        , m_exerciseView(new QQuickView)
    {
    
        connect(m_exerciseView, &QQuickView::statusChanged, [this] (QQuickView::Status status) {
            qDebug() << "STATUS -> " << status;
            if (status == QQuickView::Error) {
                qDebug() << "ERROR -> " << m_exerciseView->errors();
            }
    
            if (status == QQuickView::Ready) {
                qDebug() << "IM READY TO LOAD";
            }
        });
    
        projectToSecondScreen(QUrl("qrc:/qml/default/main.qml"));
    }
    
    void Core::projectToSecondScreen(const QUrl &source)
    {
        if (QGuiApplication::screens().count() > 1) {
            // check that the view is on the correct screen
            if (m_exerciseView->screen() != QGuiApplication::screens().at(1)) {
                m_exerciseView->setScreen(QGuiApplication::screens().at(1));
                m_exerciseView->showFullScreen();
            }
    
            // show quick view on the second screen
            // clean old
            if (!m_exerciseView->source().isEmpty()) {
                m_exerciseView->setSource(QUrl());
                m_exerciseView->engine()->clearComponentCache();
            }
    
            m_exerciseView->setSource(source);
        } else {
            QMessageBox::warning(nullptr, tr("Setup Error"), tr("No projector detected"));
        }
    }
    

    Hope this helps


  • Moderators

    @nwoki said in QQuickView hangs on delayed "setSource":
    does it work when you remove the line with m_exerciseView->setScreen(...)

    What is the output on the console? Especially with your debug prints in it.



  • same thing. It hangs and then crashes.

    STATUS:  QQmlComponent::Status(Loading)
    

    (plus other debug from other classes not related to this method. I see on the debugger that the application breaks on the "setSource" line)

    0_1473683328567_debug.png



  • I also use a QQmlComponent for loading a qml file. I use this file for the application settings (i exploit the QmlEngine for this so I can get away easy with creating my settings files as if they were qml files).

    m_mcdeSettingsComponent(new QQmlComponent(m_settingsEngine, this));
    m_mcdeSettingsComponent->loadUrl(QUrl::fromLocalFile(QApplication::applicationDirPath() + QDir::separator() + "config.rc"), QQmlComponent::Asynchronous);
    
    
    
    void Core::onSettingsComponentStatusChanged(const QQmlComponent::Status &status)
    {
        ...
        ...
       // here i create my component with:
       if (status == QQmlComponent::Ready) {
          m_mcdeSettingsComponent->create();
    
          // other operations
          ...
        } else {
           ...
        }
    }
    

    Seeing as i load them both at the same time (the settings and the quickview) could it be that for some reason they mess up with each other?

    SOLUTION: i added the "projectToSecondScreen" call at the end of the loading of the QQmlComponent i use for loading my qml plugins i use and all is well. The QQuickView is correctly created and shown.
    ( or load the QQmlComponent with QQmlCompnent::PreferSynchronous)

    QUESTION
    Why does this error occur? What happens during the loading of the QQmlComponent that messes up the loading of the QQuickView if done simultaneously?


Log in to reply
 

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