Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmlengine.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 QQMLENGINE_H
5#define QQMLENGINE_H
6
7#include <QtCore/qurl.h>
8#include <QtCore/qobject.h>
9#include <QtCore/qmap.h>
10#include <QtQml/qjsengine.h>
11#include <QtQml/qqml.h>
12#include <QtQml/qqmlerror.h>
13#include <QtQml/qqmlabstracturlinterceptor.h>
14
16
17class Q_QML_EXPORT QQmlImageProviderBase : public QObject
18{
20public:
28
29 enum Flag {
30 ForceAsynchronousImageLoading = 0x01
31 };
33
34 virtual ~QQmlImageProviderBase();
35
36 virtual ImageType imageType() const = 0;
37 virtual Flags flags() const = 0;
38
39private:
40 friend class QQuickImageProvider;
42};
43Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlImageProviderBase::Flags)
44
45class QQmlComponent;
47class QQmlExpression;
48class QQmlContext;
49class QQmlType;
50class QUrl;
51#if QT_CONFIG(qml_network)
53class QQmlNetworkAccessManagerFactory;
54#endif
56class Q_QML_EXPORT QQmlEngine : public QJSEngine
57{
58 Q_PROPERTY(QString offlineStoragePath READ offlineStoragePath WRITE setOfflineStoragePath NOTIFY offlineStoragePathChanged)
60public:
61 explicit QQmlEngine(QObject *p = nullptr);
62 ~QQmlEngine() override;
63
64 QQmlContext *rootContext() const;
65
66 void clearComponentCache();
67 void trimComponentCache();
68 void clearSingletons();
69
70 QStringList importPathList() const;
71 void setImportPathList(const QStringList &paths);
72 void addImportPath(const QString& dir);
73
74 QStringList pluginPathList() const;
75 void setPluginPathList(const QStringList &paths);
76 void addPluginPath(const QString& dir);
77
78#if QT_DEPRECATED_SINCE(6, 0)
79 QT_DEPRECATED bool addNamedBundle(const QString &, const QString &) { return false; }
80#endif
81
82#if QT_CONFIG(library)
83#if QT_DEPRECATED_SINCE(6, 4)
84 QT_DEPRECATED_VERSION_X_6_4("Import the module from QML instead")
85 bool importPlugin(const QString &filePath, const QString &uri, QList<QQmlError> *errors);
86#endif
87#endif
88
89#if QT_CONFIG(qml_network)
90 void setNetworkAccessManagerFactory(QQmlNetworkAccessManagerFactory *);
91 QQmlNetworkAccessManagerFactory *networkAccessManagerFactory() const;
92
93 QNetworkAccessManager *networkAccessManager() const;
94#endif
95
96#if QT_DEPRECATED_SINCE(6, 0)
97 QT_DEPRECATED void setUrlInterceptor(QQmlAbstractUrlInterceptor* urlInterceptor)
98 {
99 addUrlInterceptor(urlInterceptor);
100 }
101 QT_DEPRECATED QQmlAbstractUrlInterceptor *urlInterceptor() const;
102#endif
103
104 void addUrlInterceptor(QQmlAbstractUrlInterceptor *urlInterceptor);
105 void removeUrlInterceptor(QQmlAbstractUrlInterceptor *urlInterceptor);
106 QList<QQmlAbstractUrlInterceptor *> urlInterceptors() const;
107 QUrl interceptUrl(const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) const;
108
109 void addImageProvider(const QString &id, QQmlImageProviderBase *);
110 QQmlImageProviderBase *imageProvider(const QString &id) const;
111 void removeImageProvider(const QString &id);
112
113 void setIncubationController(QQmlIncubationController *);
114 QQmlIncubationController *incubationController() const;
115
116 void setOfflineStoragePath(const QString& dir);
117 QString offlineStoragePath() const;
118 QString offlineStorageDatabaseFilePath(const QString &databaseName) const;
119
120 QUrl baseUrl() const;
121 void setBaseUrl(const QUrl &);
122
123 bool outputWarningsToStandardError() const;
124 void setOutputWarningsToStandardError(bool);
125
126 void markCurrentFunctionAsTranslationBinding();
127
128 template<typename T>
129 T singletonInstance(int qmlTypeId);
130
131 template<typename T>
132 T singletonInstance(QAnyStringView moduleName, QAnyStringView typeName);
133
134 void captureProperty(QObject *object, const QMetaProperty &property) const;
135
136public Q_SLOTS:
137 void retranslate();
138
141
142public:
143 static QQmlContext *contextForObject(const QObject *);
144 static void setContextForObject(QObject *, QQmlContext *);
145
146protected:
148 bool event(QEvent *) override;
149
151 void quit();
152 void exit(int retCode);
153 void warnings(const QList<QQmlError> &warnings);
154
155private:
156 Q_DISABLE_COPY(QQmlEngine)
157 Q_DECLARE_PRIVATE(QQmlEngine)
158};
159
160template<>
161Q_QML_EXPORT QJSValue QQmlEngine::singletonInstance<QJSValue>(int qmlTypeId);
162
163template<typename T>
165 return qobject_cast<T>(singletonInstance<QJSValue>(qmlTypeId).toQObject());
166}
167
168template<>
169Q_QML_EXPORT QJSValue QQmlEngine::singletonInstance<QJSValue>(QAnyStringView uri, QAnyStringView typeName);
170
171template<typename T>
173{
174 return qobject_cast<T>(singletonInstance<QJSValue>(uri, typeName).toQObject());
175}
176
178
179#endif // QQMLENGINE_H
\inmodule QtCore
\inmodule QtCore
Definition qcoreevent.h:45
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
Definition qlist.h:75
\inmodule QtCore
The QNetworkAccessManager class allows the application to send network requests and receive replies.
\inmodule QtCore
Definition qobject.h:103
DataType
Specifies where URL interception is taking place.
The QQmlComponent class encapsulates a QML component definition.
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
void offlineStoragePathChanged()
This signal is emitted when \l offlineStoragePath changes.
void warnings(const QList< QQmlError > &warnings)
This signal is emitted when warnings messages are generated by QML.
void quit()
This signal is emitted when the QML loaded by the engine would like to quit.
void exit(int retCode)
This signal is emitted when the QML loaded by the engine would like to exit from the event loop with ...
T singletonInstance(int qmlTypeId)
\qmlproperty string Qt::uiLanguage
Definition qqmlengine.h:164
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
The QQmlExpression class evaluates JavaScript in a QML context.
The QQmlImageProviderBase class is used to register image providers in the QML engine.
Definition qqmlengine.h:18
virtual Flags flags() const =0
Implement this to return the properties of this image provider.
virtual ImageType imageType() const =0
Implement this method to return the image type supported by this image provider.
Flag
Defines specific requirements or features of this image provider.
Definition qqmlengine.h:29
ImageType
Defines the type of image supported by this image provider.
Definition qqmlengine.h:21
QQmlIncubationController instances drive the progress of QQmlIncubators.
The QQuickImageProvider class provides an interface for supporting pixmaps and threaded image request...
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Definition qurl.h:94
Combined button and popup list for selecting options.
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
Flags
@ Invalid
const char * typeName
GLenum type
GLsizei const GLuint * paths
struct _cl_event * event
GLfloat GLfloat p
[1]
int qmlTypeId(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
Definition qqml.cpp:357
#define QT_DEPRECATED_VERSION_X_6_4(text)
#define QT_DEPRECATED
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
const char property[13]
Definition qwizard.cpp:101
QUrl url("example.com")
[constructor-url-reference]
QUrl baseUrl
QString dir
[11]