Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlcomponent.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QQMLCOMPONENT_H
6#define QQMLCOMPONENT_H
7
8#include <QtCore/qvariant.h>
9#include <QtCore/qmap.h>
10
11#include <QtQml/qqml.h>
12#include <QtQml/qqmlerror.h>
13
14#include <QtCore/qobject.h>
15#include <QtCore/qstring.h>
16#include <QtQml/qjsvalue.h>
17
18QT_BEGIN_NAMESPACE
19
20
21class QByteArray;
22class QQmlEngine;
23class QQmlComponent;
24class QQmlIncubator;
25class QQmlComponentPrivate;
26class QQmlComponentAttached;
27
28namespace QV4 {
29class ExecutableCompilationUnit;
30}
31
32class Q_QML_EXPORT QQmlComponent : public QObject
33{
34 Q_OBJECT
35 Q_DECLARE_PRIVATE(QQmlComponent)
36
37 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
38 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
39 Q_PROPERTY(QUrl url READ url CONSTANT)
40
41public:
42 enum CompilationMode { PreferSynchronous, Asynchronous };
43 Q_ENUM(CompilationMode)
44
45 QQmlComponent(QObject *parent = nullptr);
46 QQmlComponent(QQmlEngine *, QObject *parent = nullptr);
47 QQmlComponent(QQmlEngine *, const QString &fileName, QObject *parent = nullptr);
48 QQmlComponent(QQmlEngine *, const QString &fileName, CompilationMode mode, QObject *parent = nullptr);
49 QQmlComponent(QQmlEngine *, const QUrl &url, QObject *parent = nullptr);
50 QQmlComponent(QQmlEngine *, const QUrl &url, CompilationMode mode, QObject *parent = nullptr);
51
52 explicit QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent = nullptr);
53 explicit QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent = nullptr);
54
55 ~QQmlComponent() override;
56
57 enum Status { Null, Ready, Loading, Error };
58 Q_ENUM(Status)
59 Status status() const;
60
61 bool isNull() const;
62 bool isReady() const;
63 bool isError() const;
64 bool isLoading() const;
65
66 bool isBound() const;
67
68 QList<QQmlError> errors() const;
69 Q_INVOKABLE QString errorString() const;
70
71 qreal progress() const;
72
73 QUrl url() const;
74
75 virtual QObject *create(QQmlContext *context = nullptr);
76 QObject *createWithInitialProperties(const QVariantMap& initialProperties, QQmlContext *context = nullptr);
77 void setInitialProperties(QObject *component, const QVariantMap &properties);
78 virtual QObject *beginCreate(QQmlContext *);
79 virtual void completeCreate();
80
81 void create(QQmlIncubator &, QQmlContext *context = nullptr,
82 QQmlContext *forContext = nullptr);
83
84 QQmlContext *creationContext() const;
85 QQmlEngine *engine() const;
86
87 static QQmlComponentAttached *qmlAttachedProperties(QObject *);
88
89public Q_SLOTS:
90 void loadUrl(const QUrl &url);
91 void loadUrl(const QUrl &url, CompilationMode mode);
92 void loadFromModule(QAnyStringView uri, QAnyStringView typeName,
93 QQmlComponent::CompilationMode mode = PreferSynchronous);
94 void setData(const QByteArray &, const QUrl &baseUrl);
95
96Q_SIGNALS:
97 void statusChanged(QQmlComponent::Status);
98 void progressChanged(qreal);
99
100protected:
101 QQmlComponent(QQmlComponentPrivate &dd, QObject* parent);
102
103#if QT_DEPRECATED_SINCE(6, 3)
104 QT_DEPRECATED_X("Use the overload with proper arguments")
105 Q_INVOKABLE void createObject(QQmlV4FunctionPtr);
106#endif
107
108 Q_INVOKABLE QObject *createObject(
109 QObject *parent = nullptr, const QVariantMap &properties = {});
110 Q_INVOKABLE void incubateObject(QQmlV4FunctionPtr);
111
112private:
113 QQmlComponent(QQmlEngine *, QV4::ExecutableCompilationUnit *compilationUnit, int,
114 QObject *parent);
115
116 Q_DISABLE_COPY(QQmlComponent)
117 friend class QQmlTypeData;
118 friend class QQmlObjectCreator;
119};
120
121
122// Don't do this at home.
123namespace QQmlPrivate {
124
125// Generally you cannot use QQmlComponentAttached as attached properties object in derived classes.
126// It is private.
127template<class T>
129{
130 using Type = void;
131};
132
133// QQmlComponent itself is allowed to use QQmlComponentAttached, though.
134template<>
139
140} // namespace QQmlPrivate
141
142QT_END_NAMESPACE
143
144#endif // QQMLCOMPONENT_H
\inmodule QtCore
Definition qobject.h:106
void setInitialState(QObject *o) override
Called after the object is first created, but before complex property bindings are evaluated and,...
void statusChanged(Status s) override
Called when the status of the incubator changes.
QQmlComponentIncubator(QV4::Heap::QmlIncubatorObject *inc, IncubationMode mode)
QV4::PersistentValue incubatorObject
The QQmlComponent class encapsulates a QML component definition.
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:19
Status
Specifies the status of the QQmlIncubator.
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
Definition qjsvalue.h:24
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
static void removePendingQPropertyBinding(QV4::Value *object, const QString &propertyName, const QQmlObjectCreator *creator)
static void QQmlComponent_setQmlParent(QObject *me, QObject *parent)
DEFINE_OBJECT_VTABLE(QV4::QmlIncubatorObject)
V4_DEFINE_EXTENSION(QQmlComponentExtension, componentExtension)
static QQmlParserStatus * parserStatusCast(const QQmlType &type, QObject *rv)
static ReturnedValue method_set_statusChanged(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_status(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_object(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void statusChanged(QQmlIncubator::Status)
void setInitialState(QObject *, RequiredProperties *requiredProperties)
static ReturnedValue method_forceCompletion(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)