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
4#ifndef QQMLCOMPONENT_H
5#define QQMLCOMPONENT_H
6
7#include <QtCore/qvariant.h>
8#include <QtCore/qmap.h>
9
10#include <QtQml/qqml.h>
11#include <QtQml/qqmlerror.h>
12
13#include <QtCore/qobject.h>
14#include <QtCore/qstring.h>
15#include <QtQml/qjsvalue.h>
16
17QT_BEGIN_NAMESPACE
18
19
20class QByteArray;
21class QQmlEngine;
22class QQmlComponent;
23class QQmlIncubator;
24class QQmlComponentPrivate;
25class QQmlComponentAttached;
26
27namespace QV4 {
28class ExecutableCompilationUnit;
29}
30
31class Q_QML_EXPORT QQmlComponent : public QObject
32{
33 Q_OBJECT
34 Q_DECLARE_PRIVATE(QQmlComponent)
35
36 Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)
37 Q_PROPERTY(Status status READ status NOTIFY statusChanged)
38 Q_PROPERTY(QUrl url READ url CONSTANT)
39
40public:
41 enum CompilationMode { PreferSynchronous, Asynchronous };
42 Q_ENUM(CompilationMode)
43
44 QQmlComponent(QObject *parent = nullptr);
45 QQmlComponent(QQmlEngine *, QObject *parent = nullptr);
46 QQmlComponent(QQmlEngine *, const QString &fileName, QObject *parent = nullptr);
47 QQmlComponent(QQmlEngine *, const QString &fileName, CompilationMode mode, QObject *parent = nullptr);
48 QQmlComponent(QQmlEngine *, const QUrl &url, QObject *parent = nullptr);
49 QQmlComponent(QQmlEngine *, const QUrl &url, CompilationMode mode, QObject *parent = nullptr);
50
51 explicit QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, QObject *parent = nullptr);
52 explicit QQmlComponent(QQmlEngine *engine, QAnyStringView uri, QAnyStringView typeName, CompilationMode mode, QObject *parent = nullptr);
53
54 ~QQmlComponent() override;
55
56 enum Status { Null, Ready, Loading, Error };
57 Q_ENUM(Status)
58 Status status() const;
59
60 bool isNull() const;
61 bool isReady() const;
62 bool isError() const;
63 bool isLoading() const;
64
65 bool isBound() const;
66
67 QList<QQmlError> errors() const;
68 Q_INVOKABLE QString errorString() const;
69
70 qreal progress() const;
71
72 QUrl url() const;
73
74 virtual QObject *create(QQmlContext *context = nullptr);
75 QObject *createWithInitialProperties(const QVariantMap& initialProperties, QQmlContext *context = nullptr);
76 void setInitialProperties(QObject *component, const QVariantMap &properties);
77 virtual QObject *beginCreate(QQmlContext *);
78 virtual void completeCreate();
79
80 void create(QQmlIncubator &, QQmlContext *context = nullptr,
81 QQmlContext *forContext = nullptr);
82
83 QQmlContext *creationContext() const;
84 QQmlEngine *engine() const;
85
86 static QQmlComponentAttached *qmlAttachedProperties(QObject *);
87
88public Q_SLOTS:
89 void loadUrl(const QUrl &url);
90 void loadUrl(const QUrl &url, CompilationMode mode);
91 void loadFromModule(QAnyStringView uri, QAnyStringView typeName,
92 QQmlComponent::CompilationMode mode = PreferSynchronous);
93 void setData(const QByteArray &, const QUrl &baseUrl);
94
95Q_SIGNALS:
96 void statusChanged(QQmlComponent::Status);
97 void progressChanged(qreal);
98
99protected:
100 QQmlComponent(QQmlComponentPrivate &dd, QObject* parent);
101
102#if QT_DEPRECATED_SINCE(6, 3)
103 QT_DEPRECATED_X("Use the overload with proper arguments")
104 Q_INVOKABLE void createObject(QQmlV4FunctionPtr);
105#endif
106
107 Q_INVOKABLE QObject *createObject(
108 QObject *parent = nullptr, const QVariantMap &properties = {});
109 Q_INVOKABLE void incubateObject(QQmlV4FunctionPtr);
110
111private:
112 QQmlComponent(QQmlEngine *, QV4::ExecutableCompilationUnit *compilationUnit, int,
113 QObject *parent);
114
115 Q_DISABLE_COPY(QQmlComponent)
116 friend class QQmlTypeData;
117 friend class QQmlObjectCreator;
118};
119
120
121// Don't do this at home.
122namespace QQmlPrivate {
123
124// Generally you cannot use QQmlComponentAttached as attached properties object in derived classes.
125// It is private.
126template<class T>
128{
129 using Type = void;
130};
131
132// QQmlComponent itself is allowed to use QQmlComponentAttached, though.
133template<>
138
139} // namespace QQmlPrivate
140
141QT_END_NAMESPACE
142
143#endif // QQMLCOMPONENT_H
\inmodule QtCore
Definition qobject.h:105
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:18
Status
Specifies the status of the QQmlIncubator.
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
Definition qjsvalue.h:23
Q_STATIC_LOGGING_CATEGORY(lcAccessibilityCore, "qt.accessibility.core")
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)