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. QQuickView hangs on delayed "setSource"

QQuickView hangs on delayed "setSource"

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qtquickqmlqt5
6 Posts 2 Posters 3.7k Views 1 Watching
  • 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.
  • N Offline
    N Offline
    nwoki
    wrote on last edited by
    #1

    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?

    raven-worxR 1 Reply Last reply
    0
    • N nwoki

      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?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nwoki
        wrote on last edited by
        #3

        @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

        raven-worxR 1 Reply Last reply
        0
        • N nwoki

          @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

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

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

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nwoki
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nwoki
              wrote on last edited by nwoki
              #6

              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?

              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