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. QQuickWidget why different behavior ?

QQuickWidget why different behavior ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
8 Posts 2 Posters 1.3k 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.
  • a-r-tA Offline
    a-r-tA Offline
    a-r-t
    wrote on last edited by a-r-t
    #1

    when i set the QQuickWidget in the ui design the qml displays the map correctly.
    when i initialize the QQuickWidget manual in the code i have nothing.
    what am i doing wrong ?

    the one working way :

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ...
    }
    

    the other not working way : ?

        m_view = new QQuickWidget(QUrl::fromLocalFile(":/qml/MapView.qml"), this);
        m_view->setGeometry(0,0,400,500);
        m_view->show();
    

    what is wrong here ?

    this is the file MapView.qml

    Item
    {
        id: window
    
        Plugin
        {
            id: mapPlugin
            name: "osm"
        }
    
        Map
        {
            id: map
            anchors.fill: parent
            plugin: mapPlugin
            center: QtPositioning.coordinate(38, 23)
            zoomLevel: 8
        }
    }
    
    

    thanks !

    JKSHJ 1 Reply Last reply
    0
    • a-r-tA a-r-t

      when i set the QQuickWidget in the ui design the qml displays the map correctly.
      when i initialize the QQuickWidget manual in the code i have nothing.
      what am i doing wrong ?

      the one working way :

      MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          ...
      }
      

      the other not working way : ?

          m_view = new QQuickWidget(QUrl::fromLocalFile(":/qml/MapView.qml"), this);
          m_view->setGeometry(0,0,400,500);
          m_view->show();
      

      what is wrong here ?

      this is the file MapView.qml

      Item
      {
          id: window
      
          Plugin
          {
              id: mapPlugin
              name: "osm"
          }
      
          Map
          {
              id: map
              anchors.fill: parent
              plugin: mapPlugin
              center: QtPositioning.coordinate(38, 23)
              zoomLevel: 8
          }
      }
      
      

      thanks !

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @a-r-t said in QQuickWidget why different behavior ?:

      the other not working way : ?
      m_view = new QQuickWidget(QUrl::fromLocalFile(":/qml/MapView.qml"), this);
      m_view->setGeometry(0,0,400,500);
      m_view->show();

      what is wrong here ?

      What does QUrl::fromLocalFile(":/qml/MapView.qml") return?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      a-r-tA 1 Reply Last reply
      0
      • a-r-tA Offline
        a-r-tA Offline
        a-r-t
        wrote on last edited by
        #3

        thanks !

        with:
        qDebug() << QUrl::fromLocalFile(":/qml/MapView.qml");
        qDebug() << m_view->source();
        it returns:
        QUrl("file::/qml/MapView.qml")

        in mainwindow.ui it is:

        <url>
              <string>qrc:/qml/MapView.qml</string>
         </url> 
        

        also from Application Output i get :

        QGeoTileProviderOsm: Tileserver disabled at  QUrl("http://maps-redirect.qt.io/osm/5.8/satellite")
        QGeoTileFetcherOsm: all providers resolved
        QWaitCondition: Destroyed while threads are still waiting
        
        1 Reply Last reply
        0
        • JKSHJ JKSH

          @a-r-t said in QQuickWidget why different behavior ?:

          the other not working way : ?
          m_view = new QQuickWidget(QUrl::fromLocalFile(":/qml/MapView.qml"), this);
          m_view->setGeometry(0,0,400,500);
          m_view->show();

          what is wrong here ?

          What does QUrl::fromLocalFile(":/qml/MapView.qml") return?

          a-r-tA Offline
          a-r-tA Offline
          a-r-t
          wrote on last edited by
          #4

          @JKSH
          i have the same result using this syntax too
          QUrl("qrc:/qml/MapView.qml")

          thanks for the answer !

          JKSHJ 1 Reply Last reply
          0
          • a-r-tA a-r-t

            @JKSH
            i have the same result using this syntax too
            QUrl("qrc:/qml/MapView.qml")

            thanks for the answer !

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by JKSH
            #5

            First, try testing with a simplified QML file:

            import QtQuick 2.0
            
            Rectangle {
                width: 640
                height: 480
                color: "red"
            }
            

            @a-r-t said in QQuickWidget why different behavior ?:

            @JKSH
            i have the same result using this syntax too
            QUrl("qrc:/qml/MapView.qml")

            • QUrl::fromLocalFile() is for loading a QML file from disk.
            • QUrl("qrc:/qml/MapView.qml") is for loading a QML file from your application Resources section (as specified by the .qrc file).

            Open your .qrc file with a text editor and paste its contents here.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            a-r-tA 1 Reply Last reply
            1
            • JKSHJ JKSH

              First, try testing with a simplified QML file:

              import QtQuick 2.0
              
              Rectangle {
                  width: 640
                  height: 480
                  color: "red"
              }
              

              @a-r-t said in QQuickWidget why different behavior ?:

              @JKSH
              i have the same result using this syntax too
              QUrl("qrc:/qml/MapView.qml")

              • QUrl::fromLocalFile() is for loading a QML file from disk.
              • QUrl("qrc:/qml/MapView.qml") is for loading a QML file from your application Resources section (as specified by the .qrc file).

              Open your .qrc file with a text editor and paste its contents here.

              a-r-tA Offline
              a-r-tA Offline
              a-r-t
              wrote on last edited by
              #6

              @JKSH said in QQuickWidget why different behavior ?:

              import QtQuick 2.0

              Rectangle {
              width: 640
              height: 480
              color: "red"
              }

              yes, the above example works as expected .
              seems something doesn't like in the other qml code
              and the question remains, as it works perfect
              under the mainwindow.ui

              qrc seems to be okay
              this is the qml.qrc

              <RCC>
                  <qresource prefix="/qml">
                      <file>MapView.qml</file>
                      <file>marker.qml</file>
                  </qresource>
                  <qresource prefix="/images">
                      <file>point.png</file>
                  </qresource>
                  <qresource prefix="/">
                      <file>marker.qml</file>
                  </qresource>
              </RCC>
              

              thanks for the responce

              JKSHJ 1 Reply Last reply
              0
              • a-r-tA a-r-t

                @JKSH said in QQuickWidget why different behavior ?:

                import QtQuick 2.0

                Rectangle {
                width: 640
                height: 480
                color: "red"
                }

                yes, the above example works as expected .
                seems something doesn't like in the other qml code
                and the question remains, as it works perfect
                under the mainwindow.ui

                qrc seems to be okay
                this is the qml.qrc

                <RCC>
                    <qresource prefix="/qml">
                        <file>MapView.qml</file>
                        <file>marker.qml</file>
                    </qresource>
                    <qresource prefix="/images">
                        <file>point.png</file>
                    </qresource>
                    <qresource prefix="/">
                        <file>marker.qml</file>
                    </qresource>
                </RCC>
                

                thanks for the responce

                JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                @a-r-t Yes, your QRC file looks fine.

                Next, try putting a width and height in your top-level Item, and try simplifying your C++ code:

                int main(int argc, char *argv[])
                {
                	QApplication app(argc, argv);
                
                	QQuickWidget w(QUrl("qrc:/qml/MapView.qml"));
                	w.show();
                
                	return app.exec();
                }
                
                QGeoTileProviderOsm: Tileserver disabled at  QUrl("http://maps-redirect.qt.io/osm/5.8/satellite")
                QGeoTileFetcherOsm: all providers resolved
                QWaitCondition: Destroyed while threads are still waiting
                

                This is weird...

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                a-r-tA 1 Reply Last reply
                1
                • JKSHJ JKSH

                  @a-r-t Yes, your QRC file looks fine.

                  Next, try putting a width and height in your top-level Item, and try simplifying your C++ code:

                  int main(int argc, char *argv[])
                  {
                  	QApplication app(argc, argv);
                  
                  	QQuickWidget w(QUrl("qrc:/qml/MapView.qml"));
                  	w.show();
                  
                  	return app.exec();
                  }
                  
                  QGeoTileProviderOsm: Tileserver disabled at  QUrl("http://maps-redirect.qt.io/osm/5.8/satellite")
                  QGeoTileFetcherOsm: all providers resolved
                  QWaitCondition: Destroyed while threads are still waiting
                  

                  This is weird...

                  a-r-tA Offline
                  a-r-tA Offline
                  a-r-t
                  wrote on last edited by
                  #8

                  @JKSH
                  try putting a width and height in your top-level Item

                  you touched the wound with this direction,
                  now it opens correctly.

                  looking the why inside the "ui_mainwindow.h"
                  we see the follow code :

                  view->setResizeMode(QQuickWidget::SizeRootObjectToView);

                  that makes the whole difference, using the ui way.

                  thank you JKSH for the fruitful discussion.
                  the query resolved !

                  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