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
QQmlApplicationEngine Class Reference

QQmlApplicationEngine provides a convenient way to load an application from a single QML file. More...

#include <qqmlapplicationengine.h>

+ Inheritance diagram for QQmlApplicationEngine:
+ Collaboration diagram for QQmlApplicationEngine:

Public Slots

void load (const QUrl &url)
 Loads the root QML file located at url.
 
void load (const QString &filePath)
 Loads the root QML file located at filePath.
 
void loadFromModule (QAnyStringView uri, QAnyStringView typeName)
 Loads the QML type typeName from the module specified by uri.
 
void setInitialProperties (const QVariantMap &initialProperties)
 Sets the initialProperties with which the QML component gets initialized after it gets loaded.
 
void setExtraFileSelectors (const QStringList &extraFileSelectors)
 Sets the extraFileSelectors to be passed to the internal QQmlFileSelector used for resolving URLs to local files.
 
void loadData (const QByteArray &data, const QUrl &url=QUrl())
 Loads the QML given in data.
 
- Public Slots inherited from QQmlEngine
void retranslate ()
 Refreshes all binding expressions that use strings marked for translation.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 

Signals

void objectCreated (QObject *object, const QUrl &url)
 This signal is emitted when an object finishes loading.
 
void objectCreationFailed (const QUrl &url)
 
- Signals inherited from QQmlEngine
void offlineStoragePathChanged ()
 This signal is emitted when \l offlineStoragePath changes.
 
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 the specified return code retCode.
 
void warnings (const QList< QQmlError > &warnings)
 This signal is emitted when warnings messages are generated by QML.
 
- Signals inherited from QJSEngine
void uiLanguageChanged ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 

Public Member Functions

 QQmlApplicationEngine (QObject *parent=nullptr)
 Create a new QQmlApplicationEngine with the given parent.
 
 QQmlApplicationEngine (const QUrl &url, QObject *parent=nullptr)
 Create a new QQmlApplicationEngine and loads the QML file at the given url.
 
 QQmlApplicationEngine (QAnyStringView uri, QAnyStringView typeName, QObject *parent=nullptr)
 Create a new QQmlApplicationEngine and loads the QML type specified by uri and typeName This is provided as a convenience, and is the same as using the empty constructor and calling loadFromModule afterwards.
 
 QQmlApplicationEngine (const QString &filePath, QObject *parent=nullptr)
 Create a new QQmlApplicationEngine and loads the QML file at the given filePath, which must be a local file path.
 
 ~QQmlApplicationEngine () override
 Destroys the QQmlApplicationEngine and all QML objects it loaded.
 
QList< QObject * > rootObjects () const
 Returns a list of all the root objects instantiated by the QQmlApplicationEngine.
 
- Public Member Functions inherited from QQmlEngine
 QQmlEngine (QObject *p=nullptr)
 Create a new QQmlEngine with the given parent.
 
 ~QQmlEngine () override
 Destroys the QQmlEngine.
 
QQmlContextrootContext () const
 Returns the engine's root context.
 
void clearComponentCache ()
 Clears the engine's internal component cache.
 
void trimComponentCache ()
 Trims the engine's internal component cache.
 
void clearSingletons ()
 Clears all singletons the engine owns.
 
QStringList importPathList () const
 Returns the list of directories where the engine searches for installed modules in a URL-based directory structure.
 
void setImportPathList (const QStringList &paths)
 Sets paths as the list of directories where the engine searches for installed modules in a URL-based directory structure.
 
void addImportPath (const QString &dir)
 Adds path as a directory where the engine searches for installed modules in a URL-based directory structure.
 
QStringList pluginPathList () const
 Returns the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir file).
 
void setPluginPathList (const QStringList &paths)
 Sets the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir file) to paths.
 
void addPluginPath (const QString &dir)
 Adds path as a directory where the engine searches for native plugins for imported modules (referenced in the qmldir file).
 
void addUrlInterceptor (QQmlAbstractUrlInterceptor *urlInterceptor)
 Adds a urlInterceptor to be used when resolving URLs in QML.
 
void removeUrlInterceptor (QQmlAbstractUrlInterceptor *urlInterceptor)
 Remove a urlInterceptor that was previously added using \l addUrlInterceptor.
 
QList< QQmlAbstractUrlInterceptor * > urlInterceptors () const
 Returns the list of currently active URL interceptors.
 
QUrl interceptUrl (const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) const
 Run the current URL interceptors on the given url of the given type and return the result.
 
void addImageProvider (const QString &id, QQmlImageProviderBase *)
 Sets the provider to use for images requested via the image: url scheme, with host providerId.
 
QQmlImageProviderBaseimageProvider (const QString &id) const
 Returns the image provider set for providerId if found; otherwise returns \nullptr.
 
void removeImageProvider (const QString &id)
 Removes the image provider for providerId.
 
void setIncubationController (QQmlIncubationController *)
 Sets the engine's incubation controller.
 
QQmlIncubationControllerincubationController () const
 Returns the currently set incubation controller, or 0 if no controller has been set.
 
void setOfflineStoragePath (const QString &dir)
 
QString offlineStoragePath () const
 
QString offlineStorageDatabaseFilePath (const QString &databaseName) const
 Returns the file path where a \l{QtQuick.LocalStorage}{Local Storage} database with the identifier databaseName is (or would be) located.
 
QUrl baseUrl () const
 Return the base URL for this engine.
 
void setBaseUrl (const QUrl &)
 Set the base URL for this engine to url.
 
bool outputWarningsToStandardError () const
 Returns true if warning messages will be output to stderr in addition to being emitted by the warnings() signal, otherwise false.
 
void setOutputWarningsToStandardError (bool)
 Set whether warning messages will be output to stderr to enabled.
 
void markCurrentFunctionAsTranslationBinding ()
 
template<typename T >
singletonInstance (int qmlTypeId)
 \qmlproperty string Qt::uiLanguage
 
template<typename T >
singletonInstance (QAnyStringView moduleName, QAnyStringView typeName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the instance of a singleton type named typeName from the module specified by uri.
 
void captureProperty (QObject *object, const QMetaProperty &property) const
 
template<>
QJSValue singletonInstance (int qmlTypeId)
 
template<>
QJSValue singletonInstance (QAnyStringView uri, QAnyStringView typeName)
 
template<>
Q_QML_EXPORT QJSValue singletonInstance (int qmlTypeId)
 
template<>
Q_QML_EXPORT QJSValue singletonInstance (QAnyStringView uri, QAnyStringView typeName)
 
- Public Member Functions inherited from QJSEngine
 QJSEngine ()
 Constructs a QJSEngine object.
 
 QJSEngine (QObject *parent)
 Constructs a QJSEngine object with the given parent.
 
 ~QJSEngine () override
 Destroys this QJSEngine.
 
QJSValue globalObject () const
 Returns this engine's Global Object.
 
QJSValue evaluate (const QString &program, const QString &fileName=QString(), int lineNumber=1, QStringList *exceptionStackTrace=nullptr)
 Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation.
 
QJSValue importModule (const QString &fileName)
 Imports the module located at fileName and returns a module namespace object that contains all exported variables, constants and functions as properties.
 
bool registerModule (const QString &moduleName, const QJSValue &value)
 Registers a QJSValue to serve as a module.
 
QJSValue newObject ()
 Creates a JavaScript object of class Object.
 
QJSValue newSymbol (const QString &name)
 
QJSValue newArray (uint length=0)
 Creates a JavaScript object of class Array with the given length.
 
QJSValue newQObject (QObject *object)
 Creates a JavaScript object that wraps the given QObject object, using JavaScriptOwnership.
 
QJSValue newQMetaObject (const QMetaObject *metaObject)
 
template<typename T >
QJSValue newQMetaObject ()
 
QJSValue newErrorObject (QJSValue::ErrorType errorType, const QString &message=QString())
 
template<typename T >
QJSValue toScriptValue (const T &value)
 Creates a QJSValue with the given value.
 
template<typename T >
QJSManagedValue toManagedValue (const T &value)
 Creates a QJSManagedValue with the given value.
 
template<typename T >
QJSPrimitiveValue toPrimitiveValue (const T &value)
 Creates a QJSPrimitiveValue with the given value.
 
template<typename T >
fromScriptValue (const QJSValue &value)
 Returns the given value converted to the template type {T}.
 
template<typename T >
fromManagedValue (const QJSManagedValue &value)
 Returns the given value converted to the template type {T}.
 
template<typename T >
fromPrimitiveValue (const QJSPrimitiveValue &value)
 Returns the given value converted to the template type {T}.
 
template<typename T >
fromVariant (const QVariant &value)
 Returns the given value converted to the template type {T}.
 
template<typename From , typename To >
To coerceValue (const From &from)
 Returns the given from converted to the template type {To}.
 
void collectGarbage ()
 Runs the garbage collector.
 
void installExtensions (Extensions extensions, const QJSValue &object=QJSValue())
 
void setInterrupted (bool interrupted)
 
bool isInterrupted () const
 
QV4::ExecutionEnginehandle () const
 
void throwError (const QString &message)
 Throws a run-time error (exception) with the given message.
 
void throwError (QJSValue::ErrorType errorType, const QString &message=QString())
 
void throwError (const QJSValue &error)
 
bool hasError () const
 Returns true if the last JavaScript execution resulted in an exception or if throwError() was called.
 
QJSValue catchError ()
 If an exception is currently pending, catches it and returns it as a QJSValue.
 
QString uiLanguage () const
 
void setUiLanguage (const QString &language)
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 

Additional Inherited Members

- Public Types inherited from QJSEngine
enum  ObjectOwnership { CppOwnership , JavaScriptOwnership }
 ObjectOwnership controls whether or not the JavaScript memory manager automatically destroys the QObject when the corresponding JavaScript object is garbage collected by the engine. More...
 
enum  Extension { TranslationExtension = 0x1 , ConsoleExtension = 0x2 , GarbageCollectionExtension = 0x4 , AllExtensions = 0xffffffff }
 This enum is used to specify extensions to be installed via \l installExtensions(). More...
 
- Static Public Member Functions inherited from QQmlEngine
static QQmlContextcontextForObject (const QObject *)
 Returns the QQmlContext for the object, or nullptr if no context has been set.
 
static void setContextForObject (QObject *, QQmlContext *)
 Sets the QQmlContext for the object to context.
 
- Static Public Member Functions inherited from QJSEngine
static void setObjectOwnership (QObject *, ObjectOwnership)
 Sets the ownership of object.
 
static ObjectOwnership objectOwnership (QObject *)
 Returns the ownership of object.
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QQmlEngine
 QQmlEngine (QQmlEnginePrivate &dd, QObject *p)
 
bool event (QEvent *) override
 \reimp
 
- Protected Member Functions inherited from QJSEngine
 QJSEngine (QJSEnginePrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QQmlEngine
QString offlineStoragePath
 the directory for storing offline user data
 
- Properties inherited from QJSEngine
QString uiLanguage
 the language to be used for translating user interface strings
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

QQmlApplicationEngine provides a convenient way to load an application from a single QML file.

Since
5.1 \inmodule QtQml

This class combines a QQmlEngine and QQmlComponent to provide a convenient way to load a single QML file. It also exposes some central application functionality to QML, which a C++/QML hybrid application would normally control from C++.

It can be used like so:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
return app.exec();
}
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
\macro qGuiApp
QQmlApplicationEngine provides a convenient way to load an application from a single QML file.
int main()
[0]
QApplication app(argc, argv)
[0]
QJSEngine engine
[0]

Unlike QQuickView, QQmlApplicationEngine does not automatically create a root window. If you are using visual items from Qt Quick, you will need to place them inside of a \l [QML] {Window}.

You can also use QCoreApplication with QQmlApplicationEngine, if you are not using any QML modules which require a QGuiApplication (such as QtQuick).

List of configuration changes from a default QQmlEngine:

\list

  • Connecting Qt.quit() to QCoreApplication::quit()
  • Automatically loads translation files from an i18n directory adjacent to the main QML file. \list
  • Translation files must have "qml_" prefix e.g. qml_ja_JP.qm. \endlist
  • Translations are reloaded when the QJSEngine::uiLanguage / Qt.uiLanguage property is changed.
  • Automatically sets an incubation controller if the scene contains a QQuickWindow.
  • Automatically sets a QQmlFileSelector as the url interceptor, applying file selectors to all QML files and assets. \endlist

The engine behavior can be further tweaked by using the inherited methods from QQmlEngine.

Definition at line 16 of file qqmlapplicationengine.h.

Constructor & Destructor Documentation

◆ QQmlApplicationEngine() [1/4]

QQmlApplicationEngine::QQmlApplicationEngine ( QObject * parent = nullptr)

Create a new QQmlApplicationEngine with the given parent.

You will have to call load() later in order to load a QML file.

Definition at line 278 of file qqmlapplicationengine.cpp.

References QJSEnginePrivate::addToDebugServer().

+ Here is the call graph for this function:

◆ QQmlApplicationEngine() [2/4]

QQmlApplicationEngine::QQmlApplicationEngine ( const QUrl & url,
QObject * parent = nullptr )

Create a new QQmlApplicationEngine and loads the QML file at the given url.

This is provided as a convenience, and is the same as using the empty constructor and calling load afterwards.

Definition at line 288 of file qqmlapplicationengine.cpp.

References load(), and url.

+ Here is the call graph for this function:

◆ QQmlApplicationEngine() [3/4]

QQmlApplicationEngine::QQmlApplicationEngine ( QAnyStringView uri,
QAnyStringView typeName,
QObject * parent = nullptr )
explicit

Create a new QQmlApplicationEngine and loads the QML type specified by uri and typeName This is provided as a convenience, and is the same as using the empty constructor and calling loadFromModule afterwards.

Since
6.5

Definition at line 302 of file qqmlapplicationengine.cpp.

References loadFromModule(), and typeName.

+ Here is the call graph for this function:

◆ QQmlApplicationEngine() [4/4]

QQmlApplicationEngine::QQmlApplicationEngine ( const QString & filePath,
QObject * parent = nullptr )

Create a new QQmlApplicationEngine and loads the QML file at the given filePath, which must be a local file path.

If a relative path is given then it will be interpreted as relative to the working directory of the application.

This is provided as a convenience, and is the same as using the empty constructor and calling load afterwards.

Definition at line 316 of file qqmlapplicationengine.cpp.

◆ ~QQmlApplicationEngine()

QQmlApplicationEngine::~QQmlApplicationEngine ( )
override

Destroys the QQmlApplicationEngine and all QML objects it loaded.

Definition at line 324 of file qqmlapplicationengine.cpp.

References d, and QJSEnginePrivate::removeFromDebugServer().

+ Here is the call graph for this function:

Member Function Documentation

◆ load [1/2]

void QQmlApplicationEngine::load ( const QString & filePath)
slot

Loads the root QML file located at filePath.

filePath must be a path to a local file. If filePath is a relative path, it is taken as relative to the application's working directory. The object tree defined by the file is instantiated immediately.

If an error occurs, error messages are printed with qWarning.

Definition at line 355 of file qqmlapplicationengine.cpp.

References QUrl::AssumeLocalFile, d, and QUrl::fromUserInput().

+ Here is the call graph for this function:

◆ load [2/2]

void QQmlApplicationEngine::load ( const QUrl & url)
slot

Loads the root QML file located at url.

The object tree defined by the file is created immediately for local file urls. Remote urls are loaded asynchronously, listen to the \l {QQmlApplicationEngine::objectCreated()}{objectCreated} signal to determine when the object tree is ready.

If an error occurs, the \l {QQmlApplicationEngine::objectCreated()}{objectCreated} signal is emitted with a null pointer as parameter and error messages are printed with qWarning.

Definition at line 341 of file qqmlapplicationengine.cpp.

References d, and url.

Referenced by QQmlApplicationEngine().

+ Here is the caller graph for this function:

◆ loadData

void QQmlApplicationEngine::loadData ( const QByteArray & data,
const QUrl & url = QUrl() )
slot

Loads the QML given in data.

The object tree defined by data is instantiated immediately.

If a url is specified it is used as the base url of the component. This affects relative paths within the data and error messages.

If an error occurs, error messages are printed with qWarning.

Definition at line 447 of file qqmlapplicationengine.cpp.

References d, and url.

◆ loadFromModule

void QQmlApplicationEngine::loadFromModule ( QAnyStringView uri,
QAnyStringView typeName )
slot

Loads the QML type typeName from the module specified by uri.

If the type originates from a QML file located at a remote url, the type will be loaded asynchronously. Listen to the \l {QQmlApplicationEngine::objectCreated()}{objectCreated} signal to determine when the object tree is ready.

If an error occurs, the \l {QQmlApplicationEngine::objectCreated()}{objectCreated} signal is emitted with a null pointer as parameter and error messages are printed with qWarning.

engine.loadFromModule("QtQuick", "Rectangle");
Note
The module identified by uri is searched in the \l {QML Import Path}{import path}, in the same way as if you were doing {import uri} inside a QML file. If the module cannot be located there, this function will fail.
Since
6.5
See also
QQmlComponent::loadFromModule

Definition at line 385 of file qqmlapplicationengine.cpp.

References d, and typeName.

Referenced by QQmlApplicationEngine().

+ Here is the caller graph for this function:

◆ objectCreated

QQmlApplicationEngine::objectCreated ( QObject * object,
const QUrl & url )
signal

This signal is emitted when an object finishes loading.

If loading was successful, object contains a pointer to the loaded object, otherwise the pointer is NULL.

The url to the component the object came from is also provided.

Note
If the path to the component was provided as a QString containing a relative path, the url will contain a fully resolved path to the file.

◆ objectCreationFailed

QQmlApplicationEngine::objectCreationFailed ( const QUrl & url)
signal
Since
6.4

This signal is emitted when loading finishes because an error occurred.

The url to the component that failed to load is provided as an argument.

QGuiApplication app(argc, argv);
// exit on error
engine.load(QUrl());
return app.exec();
static void exit(int retcode=0)
Tells the application to exit with a return code.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void objectCreationFailed(const QUrl &url)
\inmodule QtCore
Definition qurl.h:94
@ QueuedConnection
Note
If the path to the component was provided as a QString containing a relative path, the url will contain a fully resolved path to the file.

See also \l {QQmlApplicationEngine::objectCreated}, which will be emitted in addition to this signal (even though creation failed).

◆ rootObjects()

QList< QObject * > QQmlApplicationEngine::rootObjects ( ) const

Returns a list of all the root objects instantiated by the QQmlApplicationEngine.

This will only contain objects loaded via load() or a convenience constructor.

Note
In Qt versions prior to 5.9, this function is marked as non-{const}.

Definition at line 461 of file qqmlapplicationengine.cpp.

References d.

◆ setExtraFileSelectors

void QQmlApplicationEngine::setExtraFileSelectors ( const QStringList & extraFileSelectors)
slot

Sets the extraFileSelectors to be passed to the internal QQmlFileSelector used for resolving URLs to local files.

The extraFileSelectors are applied when the first QML file is loaded. Setting them afterwards has no effect.

See also
QQmlFileSelector
QFileSelector::setExtraSelectors
Since
6.0

Definition at line 427 of file qqmlapplicationengine.cpp.

References d, and qWarning.

◆ setInitialProperties

void QQmlApplicationEngine::setInitialProperties ( const QVariantMap & initialProperties)
slot

Sets the initialProperties with which the QML component gets initialized after it gets loaded.

EventDatabase eventDatabase;
EventMonitor eventMonitor;
engine.setInitialProperties({
{ "eventDatabase", QVariant::fromValue(&eventDatabase) },
{ "eventMonitor", QVariant::fromValue(&eventMonitor) }
});
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:536
See also
QQmlComponent::setInitialProperties
QQmlApplicationEngine::load
QQmlApplicationEngine::loadData
Since
5.14

Definition at line 412 of file qqmlapplicationengine.cpp.

References d.


The documentation for this class was generated from the following files: