QQuickView Class

The QQuickView class provides a window for displaying a Qt Quick user interface. More...

Header: #include <QQuickView>
qmake: QT += quick
Since: Qt 5.0
Inherits: QQuickWindow

This class was introduced in Qt 5.0.

Public Types

enum ResizeMode { SizeViewToRootObject, SizeRootObjectToView }
enum Status { Null, Ready, Loading, Error }

Properties

Public Functions

QQuickView::ResizeMode resizeMode() const
void setResizeMode(QQuickView::ResizeMode)
QUrl source() const
QQuickView::Status status() const

Public Slots

void setSource(const QUrl &)

Signals

void statusChanged(QQuickView::Status)

Detailed Description

This is a convenience subclass of QQuickWindow which will automatically load and display a QML scene when given the URL of the main source file. Alternatively, you can instantiate your own objects using QQmlComponent and place them in a manually setup QQuickWindow.

Typical usage:

 int main(int argc, char *argv[])
 {
     QGuiApplication app(argc, argv);

     QQuickView *view = new QQuickView;
     view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
     view->show();
     return app.exec();
 }

To receive errors related to loading and executing QML with QQuickView, you can connect to the statusChanged() signal and monitor for QQuickView::Error. The errors are available via QQuickView::errors().

QQuickView also manages sizing of the view and root object. By default, the resizeMode is SizeViewToRootObject, which will load the component and resize it to the size of the view. Alternatively the resizeMode may be set to SizeRootObjectToView which will resize the view to the size of the root object.

See also Exposing Attributes of C++ Types to QML and QQuickWidget.

Member Type Documentation

enum QQuickView::ResizeMode

This enum specifies how to resize the view.

ConstantValueDescription
QQuickView::SizeViewToRootObject0The view resizes with the root item in the QML.
QQuickView::SizeRootObjectToView1The view will automatically resize the root item to the size of the view.

enum QQuickView::Status

Specifies the loading status of the QQuickView.

ConstantValueDescription
QQuickView::Null0This QQuickView has no source set.
QQuickView::Ready1This QQuickView has loaded and created the QML component.
QQuickView::Loading2This QQuickView is loading network data.
QQuickView::Error3One or more errors has occurred. Call errors() to retrieve a list of errors.

Property Documentation

resizeMode : ResizeMode

This property holds whether the view should resize the window contents

If this property is set to SizeViewToRootObject (the default), the view resizes to the size of the root item in the QML.

If this property is set to SizeRootObjectToView, the view will automatically resize the root item to the size of the view.

Access functions:

QQuickView::ResizeMode resizeMode() const
void setResizeMode(QQuickView::ResizeMode)

See also initialSize().

source : QUrl

This property holds the URL of the source of the QML component.

Ensure that the URL provided is full and correct, in particular, use QUrl::fromLocalFile() when loading a file from the local filesystem.

Note that setting a source URL will result in the QML component being instantiated, even if the URL is unchanged from the current value.

Access functions:

QUrl source() const
void setSource(const QUrl &)

status : const Status

The component's current status.

Access functions:

QQuickView::Status status() const

Notifier signal:

void statusChanged(QQuickView::Status)