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
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(data) Binary to ASCII - this function returns a base64 encoding of data.
 
Q_INVOKABLE QString atob (const QString &data) const
 \qmlmethod string Qt::atob(data) ASCII to binary - this function decodes the base64 encoded data string and returns it.
 
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, string filepath)
 
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)
 
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 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 34 of file qqmlbuiltinfunctions_p.h.

Member Enumeration Documentation

◆ LoadingMode

Enumerator
Asynchronous 
Synchronous 

Definition at line 54 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.

References QQmlColorProvider::alpha(), colorVariantFromJSValue(), ok, and QQml_colorProvider().

+ Here is the call graph for this function:

◆ application()

QQmlApplication * QtObject::application ( )

◆ atob()

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

\qmlmethod string Qt::atob(data) ASCII to binary - this function decodes the base64 encoded data string and returns it.

Definition at line 1244 of file qqmlbuiltinfunctions.cpp.

References QByteArray::fromBase64(), and QString::fromUtf8().

+ Here is the call graph for this function:

◆ 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
QString 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 1676 of file qqmlbuiltinfunctions.cpp.

References QV4::MemoryManager::allocate(), QJSValuePrivate::fromReturnedValue(), QV4::EngineBase::memoryManager, QStringLiteral, QV4::ExecutionEngine::throwError(), and v4Engine().

+ Here is the call graph for this function:

◆ btoa()

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

\qmlmethod string Qt::btoa(data) Binary to ASCII - this function returns a base64 encoding of data.

Definition at line 1235 of file qqmlbuiltinfunctions.cpp.

◆ callLater()

void QtObject::callLater ( QQmlV4FunctionPtr args)

Definition at line 1691 of file qqmlbuiltinfunctions.cpp.

References args.

◆ 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 322 of file qqmlbuiltinfunctions.cpp.

References arg, QQmlStringConverters::colorFromString(), QVariant::fromValue(), ok, QStringLiteral, and QV4::ExecutionEngine::throwError().

+ Here is the call graph for this function:

◆ 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.

References QQmlStringConverters::colorFromString(), ok, QStringLiteral, and QV4::ExecutionEngine::throwError().

+ Here is the call graph for this function:

◆ create()

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

Definition at line 289 of file qqmlbuiltinfunctions.cpp.

References globalObject(), QV4::EngineBase::globalObject, QJSEngine::handle(), QV4::ExecutionEngine::newString(), QV4::QObjectWrapper::object(), and QStringLiteral.

+ Here is the call graph for this function:

◆ createComponent() [1/4]

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

Definition at line 1527 of file qqmlbuiltinfunctions.cpp.

References createComponent(), QObject::parent(), QQmlComponent::PreferSynchronous, and typeName.

+ Here is the call graph for this function:

◆ createComponent() [2/4]

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

Definition at line 1533 of file qqmlbuiltinfunctions.cpp.

References arg, QQmlComponent::Asynchronous, context, QString::endsWith(), engine, QQmlData::get(), QQmlComponentPrivate::get(), QString::isEmpty(), QObject::parent(), QQmlComponent::PreferSynchronous, QStringLiteral, QV4::ExecutionEngine::throwError(), QV4::ExecutionEngine::throwTypeError(), and typeName.

+ Here is the call graph for this function:

◆ 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()}.

\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 QtQuick 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 1496 of file qqmlbuiltinfunctions.cpp.

References createComponent(), QObject::parent(), QQmlComponent::PreferSynchronous, and url.

Referenced by createComponent(), and createComponent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createComponent() [4/4]

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

Definition at line 1501 of file qqmlbuiltinfunctions.cpp.

References arg, QQmlComponent::Asynchronous, context, engine, QQmlData::get(), QQmlComponentPrivate::get(), QUrl::isEmpty(), QObject::parent(), QQmlComponent::PreferSynchronous, QStringLiteral, QV4::ExecutionEngine::throwError(), and url.

+ Here is the call graph for this function:

◆ createQmlObject()

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

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

Returns a new object created from the given qml string which will have the specified parent, or null if there was an error in creating the object.

If filepath is specified, it will be used for error reporting for the created object.

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 1313 of file qqmlbuiltinfunctions.cpp.

References QV4::ExecutionEngine::callingQmlContext(), component(), context, create(), engine, QV4::Scope::engine, error, Error, QV4::Value::fromInt32(), QQmlData::get(), QQmlComponentPrivate::get(), QQmlContextData::get(), QQmlEnginePrivate::get(), QUrl::isRelative(), QUrl::isValid(), QQmlContext::isValid(), QV4::ExecutionEngine::newArrayObject(), QV4::ExecutionEngine::newErrorObject(), QV4::ExecutionEngine::newObject(), QV4::ExecutionEngine::newString(), QObject::parent(), QQmlPrivate::Parented, QQmlMetaType::parentFunctions(), Q_ASSERT, QStringLiteral, resolvedUrl(), QQmlTypeLoader::Synchronous, QV4::ExecutionEngine::throwError(), and url.

+ Here is the call graph for this function:

◆ 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.

References colorVariantFromJSValue(), QQmlColorProvider::darker(), ok, and QQml_colorProvider().

+ Here is the call graph for this function:

◆ 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 1278 of file qqmlbuiltinfunctions.cpp.

References engine, and QQmlEnginePrivate::get().

+ Here is the call graph for this function:

◆ 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.

References QQmlValueTypeProvider::createValueType(), QStringLiteral, and QV4::ExecutionEngine::throwError().

+ Here is the call graph for this function:

◆ fontFamilies()

QStringList QtObject::fontFamilies ( ) const

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

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

Definition at line 1217 of file qqmlbuiltinfunctions.cpp.

References QQmlGuiProvider::fontFamilies(), and QQml_guiProvider().

+ Here is the call graph for this function:

◆ formatDate() [1/6]

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

Definition at line 820 of file qqmlbuiltinfunctions.cpp.

References dateTime, and QV4::DateObject::dateTimeToDate().

+ Here is the call graph for this function:

◆ formatDate() [2/6]

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

Definition at line 833 of file qqmlbuiltinfunctions.cpp.

References dateTime, and QV4::DateObject::dateTimeToDate().

+ Here is the call graph for this function:

◆ formatDate() [3/6]

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

Definition at line 825 of file qqmlbuiltinfunctions.cpp.

References dateFromString(), and formatDate().

+ Here is the call graph for this function:

◆ formatDate() [4/6]

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

Definition at line 838 of file qqmlbuiltinfunctions.cpp.

References dateFromString(), and formatDate().

+ Here is the call graph for this function:

◆ formatDate() [5/6]

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

Definition at line 810 of file qqmlbuiltinfunctions.cpp.

References date.

Referenced by formatDate(), and formatDate().

+ Here is the caller graph for this function:

◆ formatDate() [6/6]

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

Definition at line 815 of file qqmlbuiltinfunctions.cpp.

References date.

◆ formatDateTime() [1/4]

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

Definition at line 1092 of file qqmlbuiltinfunctions.cpp.

References dateTime.

Referenced by formatDateTime(), and formatDateTime().

+ Here is the caller graph for this function:

◆ formatDateTime() [2/4]

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

Definition at line 1106 of file qqmlbuiltinfunctions.cpp.

References dateTime.

◆ formatDateTime() [3/4]

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

Definition at line 1097 of file qqmlbuiltinfunctions.cpp.

References dateTimeFromString(), and formatDateTime().

+ Here is the call graph for this function:

◆ formatDateTime() [4/4]

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

Definition at line 1111 of file qqmlbuiltinfunctions.cpp.

References dateTimeFromString(), and formatDateTime().

+ Here is the call graph for this function:

◆ formatTime() [1/6]

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

Definition at line 920 of file qqmlbuiltinfunctions.cpp.

References dateTime, and dateTimeToTime().

+ Here is the call graph for this function:

◆ formatTime() [2/6]

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

Definition at line 939 of file qqmlbuiltinfunctions.cpp.

References dateTime, and dateTimeToTime().

+ Here is the call graph for this function:

◆ formatTime() [3/6]

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

Definition at line 925 of file qqmlbuiltinfunctions.cpp.

References formatTime(), time, and timeFromString().

+ Here is the call graph for this function:

◆ formatTime() [4/6]

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

Definition at line 944 of file qqmlbuiltinfunctions.cpp.

References formatTime(), time, and timeFromString().

+ Here is the call graph for this function:

◆ formatTime() [5/6]

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

Definition at line 915 of file qqmlbuiltinfunctions.cpp.

References time.

Referenced by formatTime(), and formatTime().

+ Here is the caller graph for this function:

◆ formatTime() [6/6]

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

Definition at line 934 of file qqmlbuiltinfunctions.cpp.

References time.

◆ 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 359 of file qqmlbuiltinfunctions.cpp.

References QQmlColorProvider::fromHslF(), and QQml_colorProvider().

+ Here is the call graph for this function:

◆ 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 381 of file qqmlbuiltinfunctions.cpp.

References QQmlColorProvider::fromHsvF(), qBound(), and QQml_colorProvider().

+ Here is the call graph for this function:

◆ include()

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

Definition at line 299 of file qqmlbuiltinfunctions.cpp.

References QV4Include::method_include(), resolvedUrl(), and url.

+ Here is the call graph for this function:

◆ inputMethod()

QObject * QtObject::inputMethod ( ) const

Definition at line 1713 of file qqmlbuiltinfunctions.cpp.

References QQmlGuiProvider::inputMethod(), and QQml_guiProvider().

+ Here is the call graph for this function:

◆ 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 311 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.

References colorVariantFromJSValue(), QQmlColorProvider::lighter(), ok, and QQml_colorProvider().

+ Here is the call graph for this function:

◆ matrix4x4() [1/3]

QVariant QtObject::matrix4x4 ( ) const

\qmlmethod matrix4x4 Qt::matrix4x4()

Returns an identity matrix4x4.

Definition at line 563 of file qqmlbuiltinfunctions.cpp.

References QQmlValueTypeProvider::createValueType(), QVariant::isValid(), and variant.

+ Here is the call graph for this function:

◆ 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.

References QQmlValueTypeProvider::createValueType(), QStringLiteral, and QV4::ExecutionEngine::throwError().

+ Here is the call graph for this function:

◆ 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.

References constructFromJSValue().

+ Here is the call graph for this function:

◆ 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 1226 of file qqmlbuiltinfunctions.cpp.

References QCryptographicHash::hash(), and QCryptographicHash::Md5.

+ Here is the call graph for this function:

◆ 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 1149 of file qqmlbuiltinfunctions.cpp.

References QQmlGuiProvider::openUrlExternally(), QQml_guiProvider(), resolvedUrl(), and url.

+ Here is the call graph for this function:

◆ 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.

References constructFromJSValue().

+ Here is the call graph for this function:

◆ 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 1260 of file qqmlbuiltinfunctions.cpp.

References engine, and QQmlEnginePrivate::get().

+ Here is the call graph for this function:

◆ 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 1180 of file qqmlbuiltinfunctions.cpp.

References engine, and url.

Referenced by createQmlObject(), include(), and openUrlExternally().

+ Here is the caller graph for this function:

◆ 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 1199 of file qqmlbuiltinfunctions.cpp.

References context, engine, QQmlData::get(), and url.

+ Here is the call graph for this function:

◆ 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 339 of file qqmlbuiltinfunctions.cpp.

References QQmlColorProvider::fromRgbF(), and QQml_colorProvider().

+ Here is the call graph for this function:

◆ 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 1718 of file qqmlbuiltinfunctions.cpp.

References QQml_guiProvider(), and QQmlGuiProvider::styleHints().

+ Here is the call graph for this function:

◆ 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 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 727 of file qqmlbuiltinfunctions.cpp.

References colorVariantFromJSValue(), ok, QQml_colorProvider(), QQmlColorProvider::tint(), and v1.

+ Here is the call graph for this function:

◆ 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 1164 of file qqmlbuiltinfunctions.cpp.

References url.

◆ 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.

References constructFromJSValue().

+ Here is the call graph for this function:

◆ 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.

References constructFromJSValue().

+ Here is the call graph for this function:

◆ 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.

References constructFromJSValue().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QV4::ExecutionEngine

friend struct QV4::ExecutionEngine
friend

Definition at line 173 of file qqmlbuiltinfunctions_p.h.

Property Documentation

◆ application

QQmlApplication * QtObject::application
read

Definition at line 37 of file qqmlbuiltinfunctions_p.h.

◆ inputMethod

QObject * QtObject::inputMethod
read

Definition at line 39 of file qqmlbuiltinfunctions_p.h.

◆ platform

QQmlPlatform * QtObject::platform
read

Definition at line 38 of file qqmlbuiltinfunctions_p.h.

◆ styleHints

QObject * QtObject::styleHints
read

Definition at line 40 of file qqmlbuiltinfunctions_p.h.


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