Solved QQuickWidget why different behavior ?
-
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 !
-
@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? -
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
-
@JKSH
i have the same result using this syntax too
QUrl("qrc:/qml/MapView.qml")thanks for the answer !
-
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.
-
@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.uiqrc 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
-
@a-r-t Yes, your QRC file looks fine.
Next, try putting a
width
andheight
in your top-levelItem
, 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...
-
@JKSH
try putting a width and height in your top-level Itemyou 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 !