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

#include <qqmlbuiltinfunctions_p.h>

Inheritance diagram for QtObject:
Collaboration diagram for QtObject:

Public Types

enum  LoadingMode { Asynchronous = 0 , Synchronous = 1 }

Public Member Functions

 Q_ENUM (LoadingMode)
Q_INVOKABLE QJSValue include (const QString &url, const QJSValue &callback=QJSValue()) const
Q_INVOKABLE bool isQtObject (const QJSValue &value) const
 \qmlmethod bool Qt::isQtObject(object)
Q_INVOKABLE QVariant color (const QString &name) const
 \qmlmethod color Qt::color(string name)
Q_INVOKABLE QVariant rgba (double r, double g, double b, double a=1) const
 \qmlmethod color Qt::rgba(real red, real green, real blue, real alpha)
Q_INVOKABLE QVariant hsla (double h, double s, double l, double a=1) const
 \qmlmethod color Qt::hsla(real hue, real saturation, real lightness, real alpha)
Q_INVOKABLE QVariant hsva (double h, double s, double v, double a=1) const
Q_INVOKABLE bool colorEqual (const QVariant &lhs, const QVariant &rhs) const
 \qmlmethod color Qt::colorEqual(color lhs, string rhs)
Q_INVOKABLE QRectF rect (double x, double y, double width, double height) const
 \qmlmethod rect Qt::rect(real x, real y, real width, real height)
Q_INVOKABLE QPointF point (double x, double y) const
 \qmlmethod point Qt::point(real x, real y)
Q_INVOKABLE QSizeF size (double width, double height) const
 \qmlmethod size Qt::size(real width, real height)
Q_INVOKABLE QVariant vector2d (double x, double y) const
 \qmlmethod vector2d Qt::vector2d(real x, real y)
Q_INVOKABLE QVariant vector3d (double x, double y, double z) const
 \qmlmethod vector3d Qt::vector3d(real x, real y, real z)
Q_INVOKABLE QVariant vector4d (double x, double y, double z, double w) const
 \qmlmethod vector4d Qt::vector4d(real x, real y, real z, real w)
Q_INVOKABLE QVariant quaternion (double scalar, double x, double y, double z) const
 \qmlmethod quaternion Qt::quaternion(real scalar, real x, real y, real z)
Q_INVOKABLE QVariant matrix4x4 () const
 \qmlmethod matrix4x4 Qt::matrix4x4()
Q_INVOKABLE QVariant matrix4x4 (double m11, double m12, double m13, double m14, double m21, double m22, double m23, double m24, double m31, double m32, double m33, double m34, double m41, double m42, double m43, double m44) const
 \qmlmethod matrix4x4 Qt::matrix4x4(real m11, real m12, real m13, real m14, real m21, real m22, real m23, real m24, real m31, real m32, real m33, real m34, real m41, real m42, real m43, real m44)
Q_INVOKABLE QVariant matrix4x4 (const QJSValue &value) const
 \qmlmethod matrix4x4 Qt::matrix4x4(var values)
Q_INVOKABLE QVariant lighter (const QJSValue &color, double factor=1.5) const
 \qmlmethod color Qt::lighter(color baseColor, real factor)
Q_INVOKABLE QVariant darker (const QJSValue &color, double factor=2.0) const
 \qmlmethod color Qt::darker(color baseColor, real factor)
Q_INVOKABLE QVariant alpha (const QJSValue &baseColor, double value) const
 \qmlmethod color Qt::alpha(color baseColor, real value)
Q_INVOKABLE QVariant tint (const QJSValue &baseColor, const QJSValue &tintColor) const
 \qmlmethod color Qt::tint(color baseColor, color tintColor)
Q_INVOKABLE QString formatDate (QDate date, const QString &format) const
Q_INVOKABLE QString formatDate (const QDateTime &dateTime, const QString &format) const
Q_INVOKABLE QString formatDate (const QString &string, const QString &format) const
Q_INVOKABLE QString formatDate (QDate date, Qt::DateFormat format) const
Q_INVOKABLE QString formatDate (const QDateTime &dateTime, Qt::DateFormat format) const
Q_INVOKABLE QString formatDate (const QString &string, Qt::DateFormat format) const
Q_INVOKABLE QString formatTime (QTime time, const QString &format) const
Q_INVOKABLE QString formatTime (const QDateTime &dateTime, const QString &format) const
Q_INVOKABLE QString formatTime (const QString &time, const QString &format) const
Q_INVOKABLE QString formatTime (QTime time, Qt::DateFormat format) const
Q_INVOKABLE QString formatTime (const QDateTime &dateTime, Qt::DateFormat format) const
Q_INVOKABLE QString formatTime (const QString &time, Qt::DateFormat format) const
Q_INVOKABLE QString formatDateTime (const QDateTime &date, const QString &format) const
Q_INVOKABLE QString formatDateTime (const QString &string, const QString &format) const
Q_INVOKABLE QString formatDateTime (const QDateTime &date, Qt::DateFormat format) const
Q_INVOKABLE QString formatDateTime (const QString &string, Qt::DateFormat format) const
Q_INVOKABLE QUrl url (const QUrl &url) const
 \qmlmethod url Qt::url(url url)
Q_INVOKABLE QUrl resolvedUrl (const QUrl &url) const
 \qmlmethod url Qt::resolvedUrl(url url)
Q_INVOKABLE QUrl resolvedUrl (const QUrl &url, QObject *context) const
 \qmlmethod url Qt::resolvedUrl(url url, object context)
Q_INVOKABLE bool openUrlExternally (const QUrl &url) const
 \qmlmethod bool Qt::openUrlExternally(url target)
Q_INVOKABLE QVariant font (const QJSValue &fontSpecifier) const
 \qmlmethod font Qt::font(object fontSpecifier)
Q_INVOKABLE QStringList fontFamilies () const
 \qmlmethod list<string> Qt::fontFamilies()
Q_INVOKABLE QString md5 (const QString &data) const
 \qmlmethod string Qt::md5(data) Returns a hex string of the md5 hash of data.
Q_INVOKABLE QString btoa (const QString &data) const
 \qmlmethod string Qt::btoa(string data)
Q_INVOKABLE QString atob (const QString &data) const
 \qmlmethod string Qt::atob(string data)
Q_INVOKABLE QByteArray btoa (const QByteArray &data) const
 \qmlmethod ArrayBuffer Qt::btoa(ArrayBuffer data)
Q_INVOKABLE QByteArray atob (const QByteArray &data) const
 \qmlmethod ArrayBuffer Qt::atob(ArrayBuffer data)
Q_INVOKABLE QByteArray btoa (const QVariantList &data) const
 \qmlmethod var Qt::btoa(var data) This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Q_INVOKABLE QByteArray atob (const QVariantList &data) const
 \qmlmethod var Qt::atob(var data) This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Q_INVOKABLE void quit () const
 \qmlmethod Qt::quit()
Q_INVOKABLE void exit (int retCode) const
 \qmlmethod Qt::exit(int retCode)
Q_INVOKABLE QObjectcreateQmlObject (const QString &qml, QObject *parent, const QUrl &url=QUrl(QStringLiteral("inline"))) const
 \qmlmethod object Qt::createQmlObject(string qml, object parent, url url)
Q_INVOKABLE QQmlComponentcreateComponent (const QUrl &url, QObject *parent) const
 \qmlmethod Component Qt::createComponent(url url, enumeration mode, QtObject parent)
Q_INVOKABLE QQmlComponentcreateComponent (const QUrl &url, QQmlComponent::CompilationMode mode=QQmlComponent::PreferSynchronous, QObject *parent=nullptr) const
Q_INVOKABLE QQmlComponentcreateComponent (const QString &moduleUri, const QString &typeName, QObject *parent) const
Q_INVOKABLE QQmlComponentcreateComponent (const QString &moduleUri, const QString &typeName, QQmlComponent::CompilationMode mode=QQmlComponent::PreferSynchronous, QObject *parent=nullptr) const
Q_INVOKABLE QJSValue binding (const QJSValue &function) const
 \qmlmethod Qt::binding(function)
Q_INVOKABLE void callLater (QQmlV4FunctionPtr args)
Q_INVOKABLE double enumStringToValue (const QJSManagedValue &enumType, const QString &string)
 \qmlmethod Qt::enumStringToValue(enumType, keyName)
Q_INVOKABLE QString enumValueToString (const QJSManagedValue &enumType, double value)
 \qmlmethod Qt::enumValueToString(enumType, keyValue)
Q_INVOKABLE QStringList enumValueToStrings (const QJSManagedValue &enumType, double value)
 \qmlmethod Qt::enumValueToStrings(enumType, keyValue)
QQmlPlatformplatform ()
QQmlApplicationapplication ()
QObjectinputMethod () const
QObjectstyleHints () const
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 event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
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 isQmlObjectType () const
 Returns whether the object has been created by the QML engine or ownership has been explicitly set via QJSEngine::setObjectOwnership().
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.

Static Public Member Functions

static QtObjectcreate (QQmlEngine *, QJSEngine *jsEngine)
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)

Properties

QQmlApplicationapplication
QQmlPlatformplatform
QObjectinputMethod
QObjectstyleHints
Properties inherited from QObject
QString objectName
 the name of this object

Friends

struct QV4::ExecutionEngine

Additional Inherited Members

Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
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.
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

Detailed Description

Definition at line 43 of file qqmlbuiltinfunctions_p.h.

Member Enumeration Documentation

◆ LoadingMode

Enumerator
Asynchronous 
Synchronous 

Definition at line 62 of file qqmlbuiltinfunctions_p.h.

Member Function Documentation

◆ alpha()

QVariant QtObject::alpha ( const QJSValue & baseColor,
double value ) const

\qmlmethod color Qt::alpha(color baseColor, real value)

Returns baseColor with an alpha value of value.

value is a real ranging from 0 (completely transparent) to 1 (completely opaque).

Definition at line 694 of file qqmlbuiltinfunctions.cpp.

◆ application()

QQmlApplication * QtObject::application ( )

◆ atob() [1/3]

QByteArray QtObject::atob ( const QByteArray & data) const

\qmlmethod ArrayBuffer Qt::atob(ArrayBuffer data)

Since
6.11

ASCII to binary — this function decodes the base64 encoded data and returns it.

You can pass any array-like as data, and it will try to convert it into a byte array. In particular this works with a list of numbers and a list of one-character strings. The most efficient way to do this, however, is passing either a QByteArray or a JavaScript ArrayBuffer object.

If the conversion fails and it turns out that the data is not of the expected form, an {Invalid Character} exception is thrown and an empty array is returned.

Definition at line 1306 of file qqmlbuiltinfunctions.cpp.

◆ atob() [2/3]

QString QtObject::atob ( const QString & data) const

\qmlmethod string Qt::atob(string data)

Deprecated
[6.11] This method performs a Latin-1 conversion of the string before decoding it and then interprets the result as UTF-8.

ASCII to binary — this function decodes the base64 encoded data string and returns it.

Deprecated
[6.11] This method performs a Latin-1 conversion of the string before decoding it and then interprets the result as UTF-8.

ASCII to binary — this function decodes the base64 encoded data string and returns it.

Definition at line 1253 of file qqmlbuiltinfunctions.cpp.

◆ atob() [3/3]

QByteArray QtObject::atob ( const QVariantList & data) const

\qmlmethod var Qt::atob(var data) This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
6.11

ASCII to binary — this function decodes the base64 encoded data and returns it.

Definition at line 1383 of file qqmlbuiltinfunctions.cpp.

◆ binding()

QJSValue QtObject::binding ( const QJSValue & function) const

\qmlmethod Qt::binding(function)

Returns a JavaScript object representing a \l{Property Binding}{property binding}, with a function that evaluates the binding.

There are two main use-cases for the function: firstly, to apply a property binding imperatively from JavaScript code:

Item {
property bool someCondition: true
property int edgePosition
Component.onCompleted: {
if (someCondition == true) {
// bind to the result of the binding expression passed to Qt.binding()
edgePosition = Qt.binding(function() { return x + width })
}
}
}

and secondly, to apply a property binding when initializing property values of dynamically constructed objects (via \l{Component::createObject()} {Component.createObject()} or \l{Loader::setSource()}{Loader.setSource()}).

For example, assuming the existence of a DynamicText component:

import QtQuick
Text {
id: textElement
width: 200
height: 200
text: "Default text"
property string dynamicText: "Dynamic text"
onTextChanged: console.log(text)
}

the output from:

Item {
id: root
property string dynamicText: "Root text"
Component.onCompleted: {
var c = Qt.createComponent("DynamicText.qml")
var obj1 = c.createObject(root, { 'text': Qt.binding(function() { return dynamicText + ' extra text' }) })
root.dynamicText = "Modified root text"
var obj2 = c.createObject(root, { 'text': Qt.binding(function() { return this.dynamicText + ' extra text' }) })
obj2.dynamicText = "Modified dynamic text"
}
}

and from:

Item {
id: root
property string dynamicText: "Root text"
Loader {
id: loaderOne
onLoaded: root.dynamicText = "Modified root text"
}
Loader {
id: loaderTwo
onLoaded: item.dynamicText = "Modified dynamic text"
}
Component.onCompleted: {
loaderOne.setSource("DynamicText.qml", { 'text': Qt.binding(function() { return dynamicText + ' extra text' }) })
loaderTwo.setSource("DynamicText.qml", { 'text': Qt.binding(function() { return this.dynamicText + ' extra text' }) })
}
}

should both be:

Root text extra text
Modified root text extra text
Dynamic text extra text
Modified dynamic text extra text

This function cannot be used in property binding declarations (see the documentation on \l{qml-javascript-assignment}{binding declarations and binding assignments}) except when the result is stored in an array bound to a var property.

Since
5.0

Definition at line 1843 of file qqmlbuiltinfunctions.cpp.

◆ btoa() [1/3]

QByteArray QtObject::btoa ( const QByteArray & data) const

\qmlmethod ArrayBuffer Qt::btoa(ArrayBuffer data)

Since
6.11

Binary to ASCII — this function returns a base64 encoding of data.

You can pass any array-like as data, and it will try to convert it into a byte array. In particular this works with a list of numbers and a list of one-character strings. The most efficient way to do this, however, is passing either a QByteArray or a JavaScript ArrayBuffer object.

If the conversion fails and it turns out that the data is not of the expected form, an {Invalid Character} exception is thrown and an empty array is returned.

Definition at line 1278 of file qqmlbuiltinfunctions.cpp.

◆ btoa() [2/3]

QString QtObject::btoa ( const QString & data) const

\qmlmethod string Qt::btoa(string data)

Deprecated
[6.11] This method performs a UTF-8 conversion of the string before encoding it.

Binary to ASCII — this function returns a base64 encoding of data.

Deprecated
[6.11] This method performs a UTF-8 conversion of the string before encoding it.

Binary to ASCII — this function returns a base64 encoding of data.

Definition at line 1238 of file qqmlbuiltinfunctions.cpp.

◆ btoa() [3/3]

QByteArray QtObject::btoa ( const QVariantList & data) const

\qmlmethod var Qt::btoa(var data) This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
6.11

Binary to ASCII — this function returns a base64 encoding of data.

Definition at line 1371 of file qqmlbuiltinfunctions.cpp.

◆ callLater()

void QtObject::callLater ( QQmlV4FunctionPtr args)

Definition at line 1859 of file qqmlbuiltinfunctions.cpp.

◆ color()

QVariant QtObject::color ( const QString & name) const

\qmlmethod color Qt::color(string name)

Returns the color corresponding to the given name (i.e. red or #ff0000). If there is no such color, null is returned.

Definition at line 324 of file qqmlbuiltinfunctions.cpp.

◆ colorEqual()

bool QtObject::colorEqual ( const QVariant & lhs,
const QVariant & rhs ) const

\qmlmethod color Qt::colorEqual(color lhs, string rhs)

Returns true if both lhs and rhs yield equal color values. Both arguments may be either color values or string values. If a string value is supplied it must be convertible to a color, as described for the \l{colorvaluetypedocs}{color} value type.

Definition at line 399 of file qqmlbuiltinfunctions.cpp.

◆ create()

QtObject * QtObject::create ( QQmlEngine * ,
QJSEngine * jsEngine )
static

Definition at line 291 of file qqmlbuiltinfunctions.cpp.

◆ createComponent() [1/4]

QQmlComponent * QtObject::createComponent ( const QString & moduleUri,
const QString & typeName,
QObject * parent ) const

Definition at line 1687 of file qqmlbuiltinfunctions.cpp.

◆ createComponent() [2/4]

QQmlComponent * QtObject::createComponent ( const QString & moduleUri,
const QString & typeName,
QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous,
QObject * parent = nullptr ) const

Definition at line 1693 of file qqmlbuiltinfunctions.cpp.

◆ createComponent() [3/4]

QQmlComponent * QtObject::createComponent ( const QUrl & url,
QObject * parent ) const

\qmlmethod Component Qt::createComponent(url url, enumeration mode, QtObject parent)

Returns a \l Component object created using the QML file at the specified url, or null if an empty string was given.

The returned component's \l Component::status property indicates whether the component was successfully created. If the status is Component.Error, see \l Component::errorString() for an error description.

If the optional mode parameter is set to Component.Asynchronous, the component will be loaded in a background thread. The Component::status property will be Component.Loading while it is loading. The status will change to Component.Ready if the component loads successfully, or Component.Error if loading fails. This parameter defaults to Component.PreferSynchronous if omitted.

If mode is set to Component.PreferSynchronous, Qt will attempt to load the component synchronously, but may end up loading it asynchronously if necessary. Scenarios that may cause asynchronous loading include, but are not limited to, the following:

\list

  • The URL refers to a network resource
  • The component is being created as a result of another component that is being loaded asynchronously \endlist

If the optional parent parameter is given, it should refer to the object that will become the parent for the created \l Component object. If no mode was passed, this can be the second argument.

Call \l {Component::createObject()}{Component.createObject()} on the returned component to create an object instance of the component.

For example:

import QtQuick
Item {
id: container
width: 300; height: 300
function loadButton() {
var component = Qt.createComponent("Button.qml");
if (component.status == Component.Ready) {
var button = component.createObject(container);
button.color = "red";
}
}
Component.onCompleted: loadButton()
}

See \l {Dynamic QML Object Creation from JavaScript} for more information on using this function.

To create a QML object from an arbitrary string of QML (instead of a file), use \l{QtQml::Qt::createQmlObject()}{Qt.createQmlObject()}.

Since
6.5 \qmlmethod Component Qt::createComponent(string moduleUri, string typeName, enumeration mode, QtObject parent) This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns a \l Component object created for the type specified by moduleUri and typeName. \qml import QtQml QtObject { id: root property Component myComponent: Qt.createComponent("QtQuick", "Rectangle", Component.Asynchronous, root) } \endqml This overload mostly behaves as the url based version, but can be used to instantiate types which do not have an URL (e.g. C++ types registered via \l {QML_ELEMENT}).
Note
In some cases, passing Component.Asynchronous won't have any effect: \list
  • The type is implemented in C++
  • The type is an inline component. \endlist If the optional parent parameter is given, it should refer to the object that will become the parent for the created \l Component object. If no mode was passed, this can be the second argument.

Definition at line 1649 of file qqmlbuiltinfunctions.cpp.

◆ createComponent() [4/4]

QQmlComponent * QtObject::createComponent ( const QUrl & url,
QQmlComponent::CompilationMode mode = QQmlComponent::PreferSynchronous,
QObject * parent = nullptr ) const

Definition at line 1661 of file qqmlbuiltinfunctions.cpp.

◆ createQmlObject()

QObject * QtObject::createQmlObject ( const QString & qml,
QObject * parent,
const QUrl & url = QUrl(QStringLiteral("inline")) ) const

\qmlmethod object Qt::createQmlObject(string qml, object parent, url url)

Compiles the given qml string into a component and then returns a new object created from that component. The new object will have the specified parent. Returns null if there was an error in creating the component or the object.

If url is specified, it will be used as URL of the component. This is useful for error reporting.

Warning
The new component will shadow any existing component of the same URL. You should not pass a URL of an existing component. In particular, by passing the URL of the surrounding QML file, you prevent access to the surrounding component from the new one.

Example (where parentItem is the id of an existing QML item):

const newObject = Qt.createQmlObject(`
import QtQuick
Rectangle {
color: "red"
width: 20
height: 20
}
`,
parentItem,
"myDynamicSnippet"
);

In the case of an error, a QQmlError object is thrown. This object has an additional property, qmlErrors, which is an array of the errors encountered. Each object in this array has the members lineNumber, columnNumber, fileName and message. For example, if the above snippet had misspelled color as 'colro' then the array would contain an object like the following: { "lineNumber" : 1, "columnNumber" : 32, "fileName" : "dynamicSnippet1", "message" : "Cannot assign to non-existent property \"colro\""}.

Note
This function returns immediately, and therefore may not work if the qml string loads new components (that is, external QML files that have not yet been loaded). If this is the case, consider using \l{QtQml::Qt::createComponent()}{Qt.createComponent()} instead.
Warning
This function is extremely slow since it has to compile the passed QML string every time it is invoked. Furthermore, it's very easy to produce invalid QML when programmatically constructing QML code. It's much better to keep your QML components as separate files and add properties and methods to customize their behavior than to produce new components by string manipulation.

See \l {Dynamic QML Object Creation from JavaScript} for more information on using this function.

Definition at line 1458 of file qqmlbuiltinfunctions.cpp.

◆ darker()

QVariant QtObject::darker ( const QJSValue & color,
double factor = 2.0 ) const

\qmlmethod color Qt::darker(color baseColor, real factor)

Returns a color darker than baseColor by the factor provided.

If the factor is greater than 1.0, this function returns a darker color. Setting factor to 3.0 returns a color that has one-third the brightness. If the factor is less than 1.0, the return color is lighter, but we recommend using the Qt.lighter() function for this purpose. If the factor is 0 or negative, the return value is unspecified.

The function converts the current RGB color to HSV, divides the value (V) component by factor and converts the color back to RGB.

If factor is not supplied, returns a color that is 50% darker than baseColor (factor 2.0).

Definition at line 680 of file qqmlbuiltinfunctions.cpp.

◆ enumStringToValue()

double QtObject::enumStringToValue ( const QJSManagedValue & enumType,
const QString & string )

\qmlmethod Qt::enumStringToValue(enumType, keyName)

Returns the numeric value of key keyName in enum enumType. If the enum could not be found, a TypeError is thrown. If the key is not an entry of the enum, a ReferenceError is thrown.

Definition at line 1871 of file qqmlbuiltinfunctions.cpp.

◆ enumValueToString()

QString QtObject::enumValueToString ( const QJSManagedValue & enumType,
double value )

\qmlmethod Qt::enumValueToString(enumType, keyValue)

Returns the string representation of a key of enum enumType that has the value keyValue. If the enum could not be found, a TypeError is thrown. If the value does not match any key of the enum, a ReferenceError is thrown.

Note
If multiple keys match the value of keyValue, which of the matching keys will be returned is unspecified. Use enumValueToStrings in that case.

Definition at line 1894 of file qqmlbuiltinfunctions.cpp.

◆ enumValueToStrings()

QStringList QtObject::enumValueToStrings ( const QJSManagedValue & enumType,
double value )

\qmlmethod Qt::enumValueToStrings(enumType, keyValue)

Returns a list of the string representation of all the keys of enum enumType that have the value keyValue. If the enum could not be found, a TypeError is thrown. If no key in the enum has value keyValue, a ReferenceError is thrown.

Definition at line 1919 of file qqmlbuiltinfunctions.cpp.

◆ exit()

void QtObject::exit ( int retCode) const

\qmlmethod Qt::exit(int retCode)

This function causes the QQmlEngine::exit(int) signal to be emitted. Within the \l {Prototyping with the QML Runtime Tool}{qml tool}, this causes the launcher application to exit with the specified return code (retCode). To exit from the event loop with a specified return code when this method is called, a C++ application can connect the QQmlEngine::exit(int) signal to the QCoreApplication::exit(int) slot.

See also
quit()

Definition at line 1417 of file qqmlbuiltinfunctions.cpp.

◆ font()

QVariant QtObject::font ( const QJSValue & fontSpecifier) const

\qmlmethod font Qt::font(object fontSpecifier)

Returns a font with the properties specified in the fontSpecifier object or the nearest matching font. The fontSpecifier object should contain key-value pairs where valid keys are the \l{fontvaluetypedocs}{font} type's subproperty names, and the values are valid values for each subproperty. Invalid keys will be ignored.

Definition at line 469 of file qqmlbuiltinfunctions.cpp.

◆ fontFamilies()

QStringList QtObject::fontFamilies ( ) const

\qmlmethod list<string> Qt::fontFamilies()

Returns a list of the font families available to the application.

Definition at line 1218 of file qqmlbuiltinfunctions.cpp.

◆ formatDate() [1/6]

QString QtObject::formatDate ( const QDateTime & dateTime,
const QString & format ) const

Definition at line 821 of file qqmlbuiltinfunctions.cpp.

◆ formatDate() [2/6]

QString QtObject::formatDate ( const QDateTime & dateTime,
Qt::DateFormat format ) const

Definition at line 834 of file qqmlbuiltinfunctions.cpp.

◆ formatDate() [3/6]

QString QtObject::formatDate ( const QString & string,
const QString & format ) const

Definition at line 826 of file qqmlbuiltinfunctions.cpp.

◆ formatDate() [4/6]

QString QtObject::formatDate ( const QString & string,
Qt::DateFormat format ) const

Definition at line 839 of file qqmlbuiltinfunctions.cpp.

◆ formatDate() [5/6]

QString QtObject::formatDate ( QDate date,
const QString & format ) const

Definition at line 811 of file qqmlbuiltinfunctions.cpp.

◆ formatDate() [6/6]

QString QtObject::formatDate ( QDate date,
Qt::DateFormat format ) const

Definition at line 816 of file qqmlbuiltinfunctions.cpp.

◆ formatDateTime() [1/4]

QString QtObject::formatDateTime ( const QDateTime & date,
const QString & format ) const

Definition at line 1093 of file qqmlbuiltinfunctions.cpp.

◆ formatDateTime() [2/4]

QString QtObject::formatDateTime ( const QDateTime & date,
Qt::DateFormat format ) const

Definition at line 1107 of file qqmlbuiltinfunctions.cpp.

◆ formatDateTime() [3/4]

QString QtObject::formatDateTime ( const QString & string,
const QString & format ) const

Definition at line 1098 of file qqmlbuiltinfunctions.cpp.

◆ formatDateTime() [4/4]

QString QtObject::formatDateTime ( const QString & string,
Qt::DateFormat format ) const

Definition at line 1112 of file qqmlbuiltinfunctions.cpp.

◆ formatTime() [1/6]

QString QtObject::formatTime ( const QDateTime & dateTime,
const QString & format ) const

Definition at line 921 of file qqmlbuiltinfunctions.cpp.

◆ formatTime() [2/6]

QString QtObject::formatTime ( const QDateTime & dateTime,
Qt::DateFormat format ) const

Definition at line 940 of file qqmlbuiltinfunctions.cpp.

◆ formatTime() [3/6]

QString QtObject::formatTime ( const QString & time,
const QString & format ) const

Definition at line 926 of file qqmlbuiltinfunctions.cpp.

◆ formatTime() [4/6]

QString QtObject::formatTime ( const QString & time,
Qt::DateFormat format ) const

Definition at line 945 of file qqmlbuiltinfunctions.cpp.

◆ formatTime() [5/6]

QString QtObject::formatTime ( QTime time,
const QString & format ) const

Definition at line 916 of file qqmlbuiltinfunctions.cpp.

◆ formatTime() [6/6]

QString QtObject::formatTime ( QTime time,
Qt::DateFormat format ) const

Definition at line 935 of file qqmlbuiltinfunctions.cpp.

◆ hsla()

QVariant QtObject::hsla ( double h,
double s,
double l,
double a = 1 ) const

\qmlmethod color Qt::hsla(real hue, real saturation, real lightness, real alpha)

Returns a color with the specified hue, saturation, lightness, and alpha components. All components should be in the range 0-1 (inclusive).

Definition at line 361 of file qqmlbuiltinfunctions.cpp.

◆ hsva()

QVariant QtObject::hsva ( double h,
double s,
double v,
double a = 1 ) const
Since
5.5 \qmlmethod color Qt::hsva(real hue, real saturation, real value, real alpha)

Returns a color with the specified hue, saturation, value and alpha components. All components should be in the range 0-1 (inclusive).

Definition at line 380 of file qqmlbuiltinfunctions.cpp.

◆ include()

QJSValue QtObject::include ( const QString & url,
const QJSValue & callback = QJSValue() ) const

Definition at line 301 of file qqmlbuiltinfunctions.cpp.

◆ inputMethod()

QObject * QtObject::inputMethod ( ) const

Definition at line 1952 of file qqmlbuiltinfunctions.cpp.

◆ isQtObject()

bool QtObject::isQtObject ( const QJSValue & value) const

\qmlmethod bool Qt::isQtObject(object)

Returns true if object is a valid reference to a Qt or QML object, false otherwise.

Definition at line 313 of file qqmlbuiltinfunctions.cpp.

◆ lighter()

QVariant QtObject::lighter ( const QJSValue & color,
double factor = 1.5 ) const

\qmlmethod color Qt::lighter(color baseColor, real factor)

Returns a color lighter than baseColor by the factor provided.

If the factor is greater than 1.0, this functions returns a lighter color. Setting factor to 1.5 returns a color that is 50% brighter. If the factor is less than 1.0, the return color is darker, but we recommend using the Qt.darker() function for this purpose. If the factor is 0 or negative, the return value is unspecified.

The function converts the current RGB color to HSV, multiplies the value (V) component by factor and converts the color back to RGB.

If factor is not supplied, returns a color that is 50% lighter than baseColor (factor 1.5).

Definition at line 657 of file qqmlbuiltinfunctions.cpp.

◆ matrix4x4() [1/3]

QVariant QtObject::matrix4x4 ( ) const

\qmlmethod matrix4x4 Qt::matrix4x4()

Returns an identity matrix4x4.

Definition at line 563 of file qqmlbuiltinfunctions.cpp.

◆ matrix4x4() [2/3]

QVariant QtObject::matrix4x4 ( const QJSValue & value) const

\qmlmethod matrix4x4 Qt::matrix4x4(var values)

Returns a matrix4x4 with the specified values. values is expected to be a JavaScript array with 16 entries.

The array indices correspond to positions in the matrix as follows:

\table \row

  • 0
  • 1
  • 2
  • 3 \row
  • 4
  • 5
  • 6
  • 7 \row
  • 8
  • 9
  • 10
  • 11 \row
  • 12
  • 13
  • 14
  • 15 \endtable

Definition at line 585 of file qqmlbuiltinfunctions.cpp.

◆ matrix4x4() [3/3]

QVariant QtObject::matrix4x4 ( double m11,
double m12,
double m13,
double m14,
double m21,
double m22,
double m23,
double m24,
double m31,
double m32,
double m33,
double m34,
double m41,
double m42,
double m43,
double m44 ) const

\qmlmethod matrix4x4 Qt::matrix4x4(real m11, real m12, real m13, real m14, real m21, real m22, real m23, real m24, real m31, real m32, real m33, real m34, real m41, real m42, real m43, real m44)

Returns a matrix4x4 with the specified values.

The arguments correspond to their positions in the matrix:

\table \row

  • m11
  • m12
  • m13
  • m14 \row
  • m21
  • m22
  • m23
  • m24 \row
  • m31
  • m32
  • m33
  • m34 \row
  • m41
  • m42
  • m43
  • m44 \endtable

Definition at line 613 of file qqmlbuiltinfunctions.cpp.

◆ md5()

QString QtObject::md5 ( const QString & data) const

\qmlmethod string Qt::md5(data) Returns a hex string of the md5 hash of data.

Definition at line 1227 of file qqmlbuiltinfunctions.cpp.

◆ openUrlExternally()

bool QtObject::openUrlExternally ( const QUrl & url) const

\qmlmethod bool Qt::openUrlExternally(url target)

Attempts to open the specified target url in an external application, based on the user's desktop preferences. Returns true if it succeeds, false otherwise.

Warning
A return value of true indicates that the application has successfully requested the operating system to open the URL in an external application. The external application may still fail to launch or fail to open the requested URL. This result will not be reported back to the application.

Definition at line 1150 of file qqmlbuiltinfunctions.cpp.

◆ platform()

QQmlPlatform * QtObject::platform ( )

◆ point()

QPointF QtObject::point ( double x,
double y ) const

\qmlmethod point Qt::point(real x, real y)

Returns a point with the specified x and y coordinates.

Definition at line 445 of file qqmlbuiltinfunctions.cpp.

◆ Q_ENUM()

QtObject::Q_ENUM ( LoadingMode )

◆ quaternion()

QVariant QtObject::quaternion ( double scalar,
double x,
double y,
double z ) const

\qmlmethod quaternion Qt::quaternion(real scalar, real x, real y, real z)

Returns a quaternion with the specified scalar, x, y, and z values.

Definition at line 553 of file qqmlbuiltinfunctions.cpp.

◆ quit()

void QtObject::quit ( ) const

\qmlmethod Qt::quit()

This function causes the QQmlEngine::quit() signal to be emitted. Within the \l {Prototyping with the QML Runtime Tool}{qml tool}, this causes the launcher application to exit; to quit a C++ application when this method is called, connect the QQmlEngine::quit() signal to the QCoreApplication::quit() slot.

See also
exit()

Definition at line 1399 of file qqmlbuiltinfunctions.cpp.

◆ rect()

QRectF QtObject::rect ( double x,
double y,
double width,
double height ) const

\qmlmethod rect Qt::rect(real x, real y, real width, real height)

Returns a rect with the top-left corner at x, y and the specified width and height.

Definition at line 435 of file qqmlbuiltinfunctions.cpp.

◆ resolvedUrl() [1/2]

QUrl QtObject::resolvedUrl ( const QUrl & url) const

\qmlmethod url Qt::resolvedUrl(url url)

Returns url resolved relative to the URL of the caller.

If there is no caller or the caller is not associated with a QML context, returns url resolved relative to the QML engine's base URL. If the QML engine has no base URL, just returns url.

See also
url()

Definition at line 1181 of file qqmlbuiltinfunctions.cpp.

◆ resolvedUrl() [2/2]

QUrl QtObject::resolvedUrl ( const QUrl & url,
QObject * context ) const

\qmlmethod url Qt::resolvedUrl(url url, object context)

Returns url resolved relative to the URL of the QML context of context. If context is not associated with a QML context, returns url resolved relative to the QML engine's base URL. If the QML engine has no base URL, just returns url.

See also
url()

Definition at line 1200 of file qqmlbuiltinfunctions.cpp.

◆ rgba()

QVariant QtObject::rgba ( double r,
double g,
double b,
double a = 1 ) const

\qmlmethod color Qt::rgba(real red, real green, real blue, real alpha)

Returns a color with the specified red, green, blue, and alpha components. All components should be in the range 0-1 (inclusive).

Definition at line 341 of file qqmlbuiltinfunctions.cpp.

◆ size()

QSizeF QtObject::size ( double w,
double h ) const

\qmlmethod size Qt::size(real width, real height)

Returns a size with the specified width and height.

Definition at line 455 of file qqmlbuiltinfunctions.cpp.

◆ styleHints()

QObject * QtObject::styleHints ( ) const

Definition at line 1957 of file qqmlbuiltinfunctions.cpp.

◆ tint()

QVariant QtObject::tint ( const QJSValue & baseColor,
const QJSValue & tintColor ) const

\qmlmethod color Qt::tint(color baseColor, color tintColor)

This function allows tinting one color (baseColor) with another (tintColor).

The tint color should usually be mostly transparent, or you will not be able to see the underlying color. The below example provides a slight red tint by having the tint color be pure red which is only 1/16th opaque.

\qml Item { Rectangle { x: 0; width: 80; height: 80 color: "lightsteelblue" } Rectangle { x: 100; width: 80; height: 80 color: Qt.tint("lightsteelblue", "#10FF0000") } } \endqml {Side-by-side representation of a light steel blue square and a light steel blue square with a tint applied}

Tint is most useful when a subtle change is intended to be conveyed due to some event; you can then use tinting to more effectively tune the visible color.

Definition at line 728 of file qqmlbuiltinfunctions.cpp.

◆ url()

QUrl QtObject::url ( const QUrl & url) const

\qmlmethod url Qt::url(url url)

Returns url verbatim. This can be used to force a type coercion to url. In contrast to Qt.resolvedUrl() this retains any relative URLs. As strings are implicitly converted to urls, the function can be called with a string as argument, and will then return a url.

See also
resolvedUrl()

Definition at line 1165 of file qqmlbuiltinfunctions.cpp.

◆ vector2d()

QVariant QtObject::vector2d ( double x,
double y ) const

\qmlmethod vector2d Qt::vector2d(real x, real y)

Returns a vector2d with the specified x and y values.

Definition at line 523 of file qqmlbuiltinfunctions.cpp.

◆ vector3d()

QVariant QtObject::vector3d ( double x,
double y,
double z ) const

\qmlmethod vector3d Qt::vector3d(real x, real y, real z)

Returns a vector3d with the specified x, y, and z values.

Definition at line 533 of file qqmlbuiltinfunctions.cpp.

◆ vector4d()

QVariant QtObject::vector4d ( double x,
double y,
double z,
double w ) const

\qmlmethod vector4d Qt::vector4d(real x, real y, real z, real w)

Returns a vector4d with the specified x, y, z, and w values.

Definition at line 543 of file qqmlbuiltinfunctions.cpp.

◆ QV4::ExecutionEngine

friend struct QV4::ExecutionEngine
friend

Definition at line 192 of file qqmlbuiltinfunctions_p.h.

Property Documentation

◆ application

QQmlApplication * QtObject::application
read

Definition at line 46 of file qqmlbuiltinfunctions_p.h.

◆ inputMethod

QObject * QtObject::inputMethod
read

Definition at line 48 of file qqmlbuiltinfunctions_p.h.

◆ platform

QQmlPlatform * QtObject::platform
read

Definition at line 47 of file qqmlbuiltinfunctions_p.h.

◆ styleHints

QObject * QtObject::styleHints
read

Definition at line 49 of file qqmlbuiltinfunctions_p.h.


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