Struct qt_gui::QOpenGLContext

source ·
#[repr(C)]
pub struct QOpenGLContext { /* private fields */ }
Expand description

The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.

C++ class: QOpenGLContext.

C++ documentation:

The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.

QOpenGLContext represents the OpenGL state of an underlying OpenGL context. To set up a context, set its screen and format such that they match those of the surface or surfaces with which the context is meant to be used, if necessary make it share resources with other contexts with setShareContext(), and finally call create(). Use the return value or isValid() to check if the context was successfully initialized.

A context can be made current against a given surface by calling makeCurrent(). When OpenGL rendering is done, call swapBuffers() to swap the front and back buffers of the surface, so that the newly rendered content becomes visible. To be able to support certain platforms, QOpenGLContext requires that you call makeCurrent() again before starting rendering a new frame, after calling swapBuffers().

If the context is temporarily not needed, such as when the application is not rendering, it can be useful to delete it in order to free resources. You can connect to the aboutToBeDestroyed() signal to clean up any resources that have been allocated with different ownership from the QOpenGLContext itself.

Once a QOpenGLContext has been made current, you can render to it in a platform independent way by using Qt's OpenGL enablers such as QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL API directly, without using the Qt enablers, although potentially at the cost of portability. The latter is necessary when wanting to use OpenGL 1.x or OpenGL ES 1.x.

For more information about the OpenGL API, refer to the official OpenGL documentation.

For an example of how to use QOpenGLContext see the OpenGL Window example.

Implementations§

source§

impl QOpenGLContext

source

pub fn about_to_be_destroyed(&self) -> Signal<()>

This signal is emitted before the underlying native OpenGL context is destroyed, such that users may clean up OpenGL resources that might otherwise be left dangling in the case of shared OpenGL contexts.

Returns a built-in Qt signal QOpenGLContext::aboutToBeDestroyed that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted before the underlying native OpenGL context is destroyed, such that users may clean up OpenGL resources that might otherwise be left dangling in the case of shared OpenGL contexts.

If you wish to make the context current in order to do clean-up, make sure to only connect to the signal using a direct connection.

source

pub unsafe fn are_sharing( first: impl CastInto<Ptr<QOpenGLContext>>, second: impl CastInto<Ptr<QOpenGLContext>> ) -> bool

Returns true if the first and second contexts are sharing OpenGL resources.

Calls C++ function: static bool QOpenGLContext::areSharing(QOpenGLContext* first, QOpenGLContext* second).

C++ documentation:

Returns true if the first and second contexts are sharing OpenGL resources.

source

pub unsafe fn create(&self) -> bool

Attempts to create the OpenGL context with the current configuration.

Calls C++ function: bool QOpenGLContext::create().

C++ documentation:

Attempts to create the OpenGL context with the current configuration.

The current configuration includes the format, the share context, and the screen.

If the OpenGL implementation on your system does not support the requested version of OpenGL context, then QOpenGLContext will try to create the closest matching version. The actual created context properties can be queried using the QSurfaceFormat returned by the format() function. For example, if you request a context that supports OpenGL 4.3 Core profile but the driver and/or hardware only supports version 3.2 Core profile contexts then you will get a 3.2 Core profile context.

Returns true if the native context was successfully created and is ready to be used with makeCurrent(), swapBuffers(), etc.

Note: If the context already exists, this function destroys the existing context first, and then creates a new one.

See also makeCurrent() and format().

source

pub unsafe fn current_context() -> QPtr<QOpenGLContext>

Returns the last context which called makeCurrent in the current thread, or 0, if no context is current.

Calls C++ function: static QOpenGLContext* QOpenGLContext::currentContext().

C++ documentation:

Returns the last context which called makeCurrent in the current thread, or 0, if no context is current.

source

pub unsafe fn default_framebuffer_object(&self) -> u32

Call this to get the default framebuffer object for the current surface.

Calls C++ function: GLuint QOpenGLContext::defaultFramebufferObject() const.

C++ documentation:

Call this to get the default framebuffer object for the current surface.

On some platforms (for instance, iOS) the default framebuffer object depends on the surface being rendered to, and might be different from 0. Thus, instead of calling glBindFramebuffer(0), you should call glBindFramebuffer(ctx->defaultFramebufferObject()) if you want your application to work across different Qt platforms.

If you use the glBindFramebuffer() in QOpenGLFunctions you do not have to worry about this, as it automatically binds the current context's defaultFramebufferObject() when 0 is passed.

Note: Widgets that render via framebuffer objects, like QOpenGLWidget and QQuickWidget, will override the value returned from this function when painting is active, because at that time the correct "default" framebuffer is the widget's associated backing framebuffer, not the platform-specific one belonging to the top-level window's surface. This ensures the expected behavior for this function and other classes relying on it (for example, QOpenGLFramebufferObject::bindDefault() or QOpenGLFramebufferObject::release()).

See also QOpenGLFramebufferObject.

source

pub unsafe fn done_current(&self)

Convenience function for calling makeCurrent with a 0 surface.

Calls C++ function: void QOpenGLContext::doneCurrent().

C++ documentation:

Convenience function for calling makeCurrent with a 0 surface.

This results in no context being current in the current thread.

See also makeCurrent() and currentContext().

source

pub unsafe fn extensions(&self) -> CppBox<QSetOfQByteArray>

Returns the set of OpenGL extensions supported by this context.

Calls C++ function: QSet<QByteArray> QOpenGLContext::extensions() const.

C++ documentation:

Returns the set of OpenGL extensions supported by this context.

The context or a sharing context must be current.

See also hasExtension().

source

pub unsafe fn extra_functions(&self) -> Ptr<QOpenGLExtraFunctions>

Get the QOpenGLExtraFunctions instance for this context.

Calls C++ function: QOpenGLExtraFunctions* QOpenGLContext::extraFunctions() const.

C++ documentation:

Get the QOpenGLExtraFunctions instance for this context.

QOpenGLContext offers this as a convenient way to access QOpenGLExtraFunctions without having to manage it manually.

The context or a sharing context must be current.

The returned QOpenGLExtraFunctions instance is ready to be used and it does not need initializeOpenGLFunctions() to be called.

Note: QOpenGLExtraFunctions contains functionality that is not guaranteed to be available at runtime. Runtime availability depends on the platform, graphics driver, and the OpenGL version requested by the application.

See also QOpenGLFunctions and QOpenGLExtraFunctions.

source

pub unsafe fn format(&self) -> CppBox<QSurfaceFormat>

Returns the format of the underlying platform context, if create() has been called.

Calls C++ function: QSurfaceFormat QOpenGLContext::format() const.

C++ documentation:

Returns the format of the underlying platform context, if create() has been called.

Otherwise, returns the requested format.

The requested and the actual format may differ. Requesting a given OpenGL version does not mean the resulting context will target exactly the requested version. It is only guaranteed that the version/profile/options combination for the created context is compatible with the request, as long as the driver is able to provide such a context.

For example, requesting an OpenGL version 3.x core profile context may result in an OpenGL 4.x core profile context. Similarly, a request for OpenGL 2.1 may result in an OpenGL 3.0 context with deprecated functions enabled. Finally, depending on the driver, unsupported versions may result in either a context creation failure or in a context for the highest supported version.

Similar differences are possible in the buffer sizes, for example, the resulting context may have a larger depth buffer than requested. This is perfectly normal.

See also setFormat().

source

pub unsafe fn functions(&self) -> Ptr<QOpenGLFunctions>

Get the QOpenGLFunctions instance for this context.

Calls C++ function: QOpenGLFunctions* QOpenGLContext::functions() const.

C++ documentation:

Get the QOpenGLFunctions instance for this context.

QOpenGLContext offers this as a convenient way to access QOpenGLFunctions without having to manage it manually.

The context or a sharing context must be current.

The returned QOpenGLFunctions instance is ready to be used and it does not need initializeOpenGLFunctions() to be called.

source

pub unsafe fn get_proc_address_q_byte_array( &self, proc_name: impl CastInto<Ref<QByteArray>> ) -> Option<extern "C" fn()>

Resolves the function pointer to an OpenGL extension function, identified by procName

Calls C++ function: void (*FN_PTR)() QOpenGLContext::getProcAddress(const QByteArray& procName) const.

C++ documentation:

Resolves the function pointer to an OpenGL extension function, identified by procName

Returns 0 if no such function can be found.

source

pub unsafe fn get_proc_address_char( &self, proc_name: *const c_char ) -> Option<extern "C" fn()>

This is an overloaded function.

Calls C++ function: void (*FN_PTR)() QOpenGLContext::getProcAddress(const char* procName) const.

C++ documentation:

This is an overloaded function.

This function was introduced in Qt 5.8.

source

pub unsafe fn global_share_context() -> QPtr<QOpenGLContext>

Returns the application-wide shared OpenGL context, if present. Otherwise, returns a null pointer.

Calls C++ function: static QOpenGLContext* QOpenGLContext::globalShareContext().

C++ documentation:

Returns the application-wide shared OpenGL context, if present. Otherwise, returns a null pointer.

This is useful if you need to upload OpenGL objects (buffers, textures, etc.) before creating or showing a QOpenGLWidget or QQuickWidget.

Note: You must set the Qt::AA_ShareOpenGLContexts flag on QGuiApplication before creating the QGuiApplication object, otherwise Qt may not create a global shared context.

Warning: Do not attempt to make the context returned by this function current on any surface. Instead, you can create a new context which shares with the global one, and then make the new context current.

This function was introduced in Qt 5.5.

See also Qt::AA_ShareOpenGLContexts, setShareContext(), and makeCurrent().

source

pub unsafe fn has_extension( &self, extension: impl CastInto<Ref<QByteArray>> ) -> bool

Returns true if this OpenGL context supports the specified OpenGL extension, false otherwise.

Calls C++ function: bool QOpenGLContext::hasExtension(const QByteArray& extension) const.

C++ documentation:

Returns true if this OpenGL context supports the specified OpenGL extension, false otherwise.

The context or a sharing context must be current.

See also extensions().

source

pub unsafe fn is_opengl_e_s(&self) -> bool

Returns true if the context is an OpenGL ES context.

Calls C++ function: bool QOpenGLContext::isOpenGLES() const.

C++ documentation:

Returns true if the context is an OpenGL ES context.

If the context has not yet been created, the result is based on the requested format set via setFormat().

This function was introduced in Qt 5.3.

See also create(), format(), and setFormat().

source

pub unsafe fn is_valid(&self) -> bool

Returns if this context is valid, i.e. has been successfully created.

Calls C++ function: bool QOpenGLContext::isValid() const.

C++ documentation:

Returns if this context is valid, i.e. has been successfully created.

On some platforms the return value of false for a context that was successfully created previously indicates that the OpenGL context was lost.

The typical way to handle context loss scenarios in applications is to check via this function whenever makeCurrent() fails and returns false. If this function then returns false, recreate the underlying native OpenGL context by calling create(), call makeCurrent() again and then reinitialize all OpenGL resources.

See also create().

source

pub unsafe fn make_current(&self, surface: impl CastInto<Ptr<QSurface>>) -> bool

Makes the context current in the current thread, against the given surface. Returns true if successful; otherwise returns false. The latter may happen if the surface is not exposed, or the graphics hardware is not available due to e.g. the application being suspended.

Calls C++ function: bool QOpenGLContext::makeCurrent(QSurface* surface).

C++ documentation:

Makes the context current in the current thread, against the given surface. Returns true if successful; otherwise returns false. The latter may happen if the surface is not exposed, or the graphics hardware is not available due to e.g. the application being suspended.

If surface is 0 this is equivalent to calling doneCurrent().

Avoid calling this function from a different thread than the one the QOpenGLContext instance lives in. If you wish to use QOpenGLContext from a different thread you should first call make sure it's not current in the current thread, by calling doneCurrent() if necessary. Then call moveToThread(otherThread) before using it in the other thread.

By default Qt employs a check that enforces the above condition on the thread affinity. It is still possible to disable this check by setting the Qt::AA_DontCheckOpenGLContextThreadAffinity application attribute. Be sure to understand the consequences of using QObjects from outside the thread they live in, as explained in the QObject thread affinity documentation.

See also functions(), doneCurrent(), and Qt::AA_DontCheckOpenGLContextThreadAffinity.

source

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>

Calls C++ function: virtual const QMetaObject* QOpenGLContext::metaObject() const.

source

pub unsafe fn native_handle(&self) -> CppBox<QVariant>

Returns the native handle for the context.

Calls C++ function: QVariant QOpenGLContext::nativeHandle() const.

C++ documentation:

Returns the native handle for the context.

This function provides access to the QOpenGLContext's underlying native context. The returned variant contains a platform-specific value type. These classes can be found in the module QtPlatformHeaders.

On platforms where retrieving the native handle is not supported, or if neither create() nor setNativeHandle() was called, a null variant is returned.

This function was introduced in Qt 5.4.

See also setNativeHandle().

source

pub unsafe fn new_1a( parent: impl CastInto<Ptr<QObject>> ) -> QBox<QOpenGLContext>

Creates a new OpenGL context instance with parent object parent.

Calls C++ function: [constructor] void QOpenGLContext::QOpenGLContext(QObject* parent = …).

C++ documentation:

Creates a new OpenGL context instance with parent object parent.

Before it can be used you need to set the proper format and call create().

See also create() and makeCurrent().

source

pub unsafe fn new_0a() -> QBox<QOpenGLContext>

The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.

Calls C++ function: [constructor] void QOpenGLContext::QOpenGLContext().

C++ documentation:

The QOpenGLContext class represents a native OpenGL context, enabling OpenGL rendering on a QSurface.

QOpenGLContext represents the OpenGL state of an underlying OpenGL context. To set up a context, set its screen and format such that they match those of the surface or surfaces with which the context is meant to be used, if necessary make it share resources with other contexts with setShareContext(), and finally call create(). Use the return value or isValid() to check if the context was successfully initialized.

A context can be made current against a given surface by calling makeCurrent(). When OpenGL rendering is done, call swapBuffers() to swap the front and back buffers of the surface, so that the newly rendered content becomes visible. To be able to support certain platforms, QOpenGLContext requires that you call makeCurrent() again before starting rendering a new frame, after calling swapBuffers().

If the context is temporarily not needed, such as when the application is not rendering, it can be useful to delete it in order to free resources. You can connect to the aboutToBeDestroyed() signal to clean up any resources that have been allocated with different ownership from the QOpenGLContext itself.

Once a QOpenGLContext has been made current, you can render to it in a platform independent way by using Qt's OpenGL enablers such as QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL API directly, without using the Qt enablers, although potentially at the cost of portability. The latter is necessary when wanting to use OpenGL 1.x or OpenGL ES 1.x.

For more information about the OpenGL API, refer to the official OpenGL documentation.

For an example of how to use QOpenGLContext see the OpenGL Window example.

source

pub unsafe fn opengl_module_handle() -> *mut c_void

Returns the platform-specific handle for the OpenGL implementation that is currently in use. (for example, a HMODULE on Windows)

Calls C++ function: static void* QOpenGLContext::openGLModuleHandle().

C++ documentation:

Returns the platform-specific handle for the OpenGL implementation that is currently in use. (for example, a HMODULE on Windows)

On platforms that do not use dynamic GL switch the return value is null.

The library might be GL-only, meaning that windowing system interface functions (for example EGL) may live in another, separate library.

Note: This function requires that the QGuiApplication instance is already created.

This function was introduced in Qt 5.3.

See also openGLModuleType().

source

pub unsafe fn opengl_module_type() -> OpenGLModuleType

Returns the underlying OpenGL implementation type.

Calls C++ function: static QOpenGLContext::OpenGLModuleType QOpenGLContext::openGLModuleType().

C++ documentation:

Returns the underlying OpenGL implementation type.

On platforms where the OpenGL implementation is not dynamically loaded, the return value is determined during compile time and never changes.

Note: A desktop OpenGL implementation may be capable of creating ES-compatible contexts too. Therefore in most cases it is more appropriate to check QSurfaceFormat::renderableType() or use the convenience function isOpenGLES().

Note: This function requires that the QGuiApplication instance is already created.

This function was introduced in Qt 5.3.

source

pub unsafe fn qt_metacall( &self, arg1: Call, arg2: c_int, arg3: *mut *mut c_void ) -> c_int

Calls C++ function: virtual int QOpenGLContext::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

source

pub unsafe fn qt_metacast(&self, arg1: *const c_char) -> *mut c_void

Calls C++ function: virtual void* QOpenGLContext::qt_metacast(const char* arg1).

source

pub unsafe fn screen(&self) -> QPtr<QScreen>

Returns the screen the context was created for.

Calls C++ function: QScreen* QOpenGLContext::screen() const.

C++ documentation:

Returns the screen the context was created for.

See also setScreen().

source

pub unsafe fn set_format(&self, format: impl CastInto<Ref<QSurfaceFormat>>)

Sets the format the OpenGL context should be compatible with. You need to call create() before it takes effect.

Calls C++ function: void QOpenGLContext::setFormat(const QSurfaceFormat& format).

C++ documentation:

Sets the format the OpenGL context should be compatible with. You need to call create() before it takes effect.

When the format is not explicitly set via this function, the format returned by QSurfaceFormat::defaultFormat() will be used. This means that when having multiple contexts, individual calls to this function can be replaced by one single call to QSurfaceFormat::setDefaultFormat() before creating the first context.

See also format().

source

pub unsafe fn set_native_handle(&self, handle: impl CastInto<Ref<QVariant>>)

Set the native handles for this context. When create() is called and a native handle is set, configuration settings, like format(), are ignored since this QOpenGLContext will wrap an already created native context instead of creating a new one from scratch.

Calls C++ function: void QOpenGLContext::setNativeHandle(const QVariant& handle).

C++ documentation:

Set the native handles for this context. When create() is called and a native handle is set, configuration settings, like format(), are ignored since this QOpenGLContext will wrap an already created native context instead of creating a new one from scratch.

On some platforms the native context handle is not sufficient and other related handles (for example, for a window or display) have to be provided in addition. Therefore handle is variant containing a platform-specific value type. These classes can be found in the QtPlatformHeaders module.

When create() is called with native handles set, QOpenGLContext does not take ownership of the handles, so destroying the QOpenGLContext does not destroy the native context.

Note: Some frameworks track the current context and surfaces internally. Making the adopted QOpenGLContext current via Qt will have no effect on such other frameworks' internal state. Therefore a subsequent makeCurrent done via the other framework may have no effect. It is therefore advisable to make explicit calls to make no context and surface current to reset the other frameworks' internal state after performing OpenGL operations via Qt.

Note: Using foreign contexts with Qt windows and Qt contexts with windows and surfaces created by other frameworks may give unexpected results, depending on the platform, due to potential mismatches in context and window pixel formats. To make sure this does not happen, avoid making contexts and surfaces from different frameworks current together. Instead, prefer approaches based on context sharing where OpenGL resources like textures are accessible both from Qt's and the foreign framework's contexts.

This function was introduced in Qt 5.4.

See also nativeHandle().

source

pub unsafe fn set_screen(&self, screen: impl CastInto<Ptr<QScreen>>)

Sets the screen the OpenGL context should be valid for. You need to call create() before it takes effect.

Calls C++ function: void QOpenGLContext::setScreen(QScreen* screen).

C++ documentation:

Sets the screen the OpenGL context should be valid for. You need to call create() before it takes effect.

See also screen().

source

pub unsafe fn set_share_context( &self, share_context: impl CastInto<Ptr<QOpenGLContext>> )

Makes this context share textures, shaders, and other OpenGL resources with shareContext. You need to call create() before it takes effect.

Calls C++ function: void QOpenGLContext::setShareContext(QOpenGLContext* shareContext).

C++ documentation:

Makes this context share textures, shaders, and other OpenGL resources with shareContext. You need to call create() before it takes effect.

See also shareContext().

source

pub unsafe fn share_context(&self) -> QPtr<QOpenGLContext>

Returns the share context this context was created with.

Calls C++ function: QOpenGLContext* QOpenGLContext::shareContext() const.

C++ documentation:

Returns the share context this context was created with.

If the underlying platform was not able to support the requested sharing, this will return 0.

See also setShareContext().

source

pub unsafe fn share_group(&self) -> QPtr<QOpenGLContextGroup>

Returns the share group this context belongs to.

Calls C++ function: QOpenGLContextGroup* QOpenGLContext::shareGroup() const.

C++ documentation:

Returns the share group this context belongs to.

source

pub unsafe fn static_meta_object() -> Ref<QMetaObject>

Returns a reference to the staticMetaObject field.

source

pub unsafe fn supports_threaded_opengl() -> bool

Returns true if the platform supports OpenGL rendering outside the main (gui) thread.

Calls C++ function: static bool QOpenGLContext::supportsThreadedOpenGL().

C++ documentation:

Returns true if the platform supports OpenGL rendering outside the main (gui) thread.

The value is controlled by the platform plugin in use and may also depend on the graphics drivers.

This function was introduced in Qt 5.5.

source

pub unsafe fn surface(&self) -> Ptr<QSurface>

Returns the surface the context has been made current with.

Calls C++ function: QSurface* QOpenGLContext::surface() const.

C++ documentation:

Returns the surface the context has been made current with.

This is the surface passed as an argument to makeCurrent().

source

pub unsafe fn swap_buffers(&self, surface: impl CastInto<Ptr<QSurface>>)

Swap the back and front buffers of surface.

Calls C++ function: void QOpenGLContext::swapBuffers(QSurface* surface).

C++ documentation:

Swap the back and front buffers of surface.

Call this to finish a frame of OpenGL rendering, and make sure to call makeCurrent() again before you begin a new frame.

source

pub unsafe fn tr( s: *const c_char, c: *const c_char, n: c_int ) -> CppBox<QString>

Calls C++ function: static QString QOpenGLContext::tr(const char* s, const char* c, int n).

source

pub unsafe fn tr_utf8( s: *const c_char, c: *const c_char, n: c_int ) -> CppBox<QString>

Calls C++ function: static QString QOpenGLContext::trUtf8(const char* s, const char* c, int n).

source

pub unsafe fn version_functions_1a( &self, version_profile: impl CastInto<Ref<QOpenGLVersionProfile>> ) -> Ptr<QAbstractOpenGLFunctions>

Returns a pointer to an object that provides access to all functions for the versionProfile of this context. There is no need to call QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context is current. It is also possible to call this function when the context is not current, but in that case it is the caller's responsibility to ensure proper initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() afterwards.

Calls C++ function: QAbstractOpenGLFunctions* QOpenGLContext::versionFunctions(const QOpenGLVersionProfile& versionProfile = …) const.

C++ documentation:

Returns a pointer to an object that provides access to all functions for the versionProfile of this context. There is no need to call QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context is current. It is also possible to call this function when the context is not current, but in that case it is the caller’s responsibility to ensure proper initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() afterwards.

Usually one would use the template version of this function to automatically have the result cast to the correct type.

source

pub unsafe fn version_functions_0a(&self) -> Ptr<QAbstractOpenGLFunctions>

Returns a pointer to an object that provides access to all functions for the versionProfile of this context. There is no need to call QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context is current. It is also possible to call this function when the context is not current, but in that case it is the caller's responsibility to ensure proper initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() afterwards.

Calls C++ function: QAbstractOpenGLFunctions* QOpenGLContext::versionFunctions() const.

C++ documentation:

Returns a pointer to an object that provides access to all functions for the versionProfile of this context. There is no need to call QAbstractOpenGLFunctions::initializeOpenGLFunctions() as long as this context is current. It is also possible to call this function when the context is not current, but in that case it is the caller’s responsibility to ensure proper initialization by calling QAbstractOpenGLFunctions::initializeOpenGLFunctions() afterwards.

Usually one would use the template version of this function to automatically have the result cast to the correct type.

Methods from Deref<Target = QObject>§

source

pub unsafe fn find_child<T>( &self, name: &str ) -> Result<QPtr<T>, FindChildError>

Finds a child of self with the specified object name and casts it to type T.

The search is performed recursively. If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned.

Returns an error if there is no child object with object name name or the found object cannot be cast to T.

source

pub fn destroyed(&self) -> Signal<(*mut QObject,)>

This signal is emitted immediately before the object obj is destroyed, and can not be blocked.

Returns a built-in Qt signal QObject::destroyed that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted immediately before the object obj is destroyed, and can not be blocked.

All the objects's children are destroyed immediately after this signal is emitted.

See also deleteLater() and QPointer.

source

pub fn object_name_changed(&self) -> Signal<(*const QString,)>

This signal is emitted after the object's name has been changed. The new object name is passed as objectName.

Returns a built-in Qt signal QObject::objectNameChanged that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted after the object’s name has been changed. The new object name is passed as objectName.

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

Note: Notifier signal for property objectName.

See also QObject::objectName.

source

pub fn slot_delete_later(&self) -> Receiver<()>

Schedules this object for deletion.

Returns a built-in Qt slot QObject::deleteLater that can be passed to qt_core::Signal::connect.

C++ documentation:

Schedules this object for deletion.

The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the event loop is started. If deleteLater() is called after the main event loop has stopped, the object will not be deleted. Since Qt 4.8, if deleteLater() is called on an object that lives in a thread with no running event loop, the object will be destroyed when the thread finishes.

Note that entering and leaving a new event loop (e.g., by opening a modal dialog) will not perform the deferred deletion; for the object to be deleted, the control must return to the event loop from which deleteLater() was called.

Note: It is safe to call this function more than once; when the first deferred deletion event is delivered, any pending events for the object are removed from the event queue.

See also destroyed() and QPointer.

source

pub unsafe fn block_signals(&self, b: bool) -> bool

If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). If block is false, no such blocking will occur.

Calls C++ function: bool QObject::blockSignals(bool b).

C++ documentation:

If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). If block is false, no such blocking will occur.

The return value is the previous value of signalsBlocked().

Note that the destroyed() signal will be emitted even if the signals for this object have been blocked.

Signals emitted while being blocked are not buffered.

See also signalsBlocked() and QSignalBlocker.

source

pub unsafe fn children(&self) -> Ref<QListOfQObject>

Returns a list of child objects. The QObjectList class is defined in the <QObject> header file as the following:

Calls C++ function: const QList<QObject*>& QObject::children() const.

C++ documentation:

Returns a list of child objects. The QObjectList class is defined in the <QObject> header file as the following:


  typedef QList<QObject*> QObjectList;

The first child added is the first object in the list and the last child added is the last object in the list, i.e. new children are appended at the end.

Note that the list order changes when QWidget children are raised or lowered. A widget that is raised becomes the last object in the list, and a widget that is lowered becomes the first object in the list.

See also findChild(), findChildren(), parent(), and setParent().

source

pub unsafe fn delete_later(&self)

Schedules this object for deletion.

Calls C++ function: [slot] void QObject::deleteLater().

C++ documentation:

Schedules this object for deletion.

The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the event loop is started. If deleteLater() is called after the main event loop has stopped, the object will not be deleted. Since Qt 4.8, if deleteLater() is called on an object that lives in a thread with no running event loop, the object will be destroyed when the thread finishes.

Note that entering and leaving a new event loop (e.g., by opening a modal dialog) will not perform the deferred deletion; for the object to be deleted, the control must return to the event loop from which deleteLater() was called.

Note: It is safe to call this function more than once; when the first deferred deletion event is delivered, any pending events for the object are removed from the event queue.

See also destroyed() and QPointer.

source

pub unsafe fn disconnect_char_q_object_char( &self, signal: *const i8, receiver: impl CastInto<Ptr<QObject>>, member: *const i8 ) -> bool

This function overloads disconnect().

Calls C++ function: bool QObject::disconnect(const char* signal = …, const QObject* receiver = …, const char* member = …) const.

C++ documentation:

This function overloads disconnect().

Disconnects signal from method of receiver.

A signal-slot connection is removed when either of the objects involved are destroyed.

Note: This function is thread-safe.

source

pub unsafe fn disconnect_q_object_char( &self, receiver: impl CastInto<Ptr<QObject>>, member: *const i8 ) -> bool

This function overloads disconnect().

Calls C++ function: bool QObject::disconnect(const QObject* receiver, const char* member = …) const.

C++ documentation:

This function overloads disconnect().

Disconnects all signals in this object from receiver's method.

A signal-slot connection is removed when either of the objects involved are destroyed.

source

pub unsafe fn disconnect_char_q_object( &self, signal: *const i8, receiver: impl CastInto<Ptr<QObject>> ) -> bool

This function overloads disconnect().

Calls C++ function: bool QObject::disconnect(const char* signal = …, const QObject* receiver = …) const.

C++ documentation:

This function overloads disconnect().

Disconnects signal from method of receiver.

A signal-slot connection is removed when either of the objects involved are destroyed.

Note: This function is thread-safe.

source

pub unsafe fn disconnect_char(&self, signal: *const i8) -> bool

This function overloads disconnect().

Calls C++ function: bool QObject::disconnect(const char* signal = …) const.

C++ documentation:

This function overloads disconnect().

Disconnects signal from method of receiver.

A signal-slot connection is removed when either of the objects involved are destroyed.

Note: This function is thread-safe.

source

pub unsafe fn disconnect(&self) -> bool

This function overloads disconnect().

Calls C++ function: bool QObject::disconnect() const.

C++ documentation:

This function overloads disconnect().

Disconnects signal from method of receiver.

A signal-slot connection is removed when either of the objects involved are destroyed.

Note: This function is thread-safe.

source

pub unsafe fn disconnect_q_object( &self, receiver: impl CastInto<Ptr<QObject>> ) -> bool

This function overloads disconnect().

Calls C++ function: bool QObject::disconnect(const QObject* receiver) const.

C++ documentation:

This function overloads disconnect().

Disconnects all signals in this object from receiver's method.

A signal-slot connection is removed when either of the objects involved are destroyed.

source

pub unsafe fn dump_object_info_mut(&self)

Dumps information about signal connections, etc. for this object to the debug output.

Calls C++ function: void QObject::dumpObjectInfo().

C++ documentation:

Dumps information about signal connections, etc. for this object to the debug output.

Note: before Qt 5.9, this function was not const.

See also dumpObjectTree().

source

pub unsafe fn dump_object_info(&self)

Dumps information about signal connections, etc. for this object to the debug output.

Calls C++ function: void QObject::dumpObjectInfo() const.

C++ documentation:

Dumps information about signal connections, etc. for this object to the debug output.

Note: before Qt 5.9, this function was not const.

See also dumpObjectTree().

source

pub unsafe fn dump_object_tree_mut(&self)

Dumps a tree of children to the debug output.

Calls C++ function: void QObject::dumpObjectTree().

C++ documentation:

Dumps a tree of children to the debug output.

Note: before Qt 5.9, this function was not const.

See also dumpObjectInfo().

source

pub unsafe fn dump_object_tree(&self)

Dumps a tree of children to the debug output.

Calls C++ function: void QObject::dumpObjectTree() const.

C++ documentation:

Dumps a tree of children to the debug output.

Note: before Qt 5.9, this function was not const.

See also dumpObjectInfo().

source

pub unsafe fn dynamic_property_names(&self) -> CppBox<QListOfQByteArray>

Returns the names of all properties that were dynamically added to the object using setProperty().

Calls C++ function: QList<QByteArray> QObject::dynamicPropertyNames() const.

C++ documentation:

Returns the names of all properties that were dynamically added to the object using setProperty().

This function was introduced in Qt 4.2.

source

pub unsafe fn eq(&self, p: impl CastInto<Ref<QPointerOfQObject>>) -> bool

Returns true if c1 and c2 are the same Unicode character; otherwise returns false.

Calls C++ function: bool operator==(QObject* o, const QPointer<QObject>& p).

Warning: no exact match found in C++ documentation. Below is the C++ documentation for bool operator==(QChar c1, QChar c2):

Returns true if c1 and c2 are the same Unicode character; otherwise returns false.

source

pub unsafe fn event(&self, event: impl CastInto<Ptr<QEvent>>) -> bool

This virtual function receives events to an object and should return true if the event e was recognized and processed.

Calls C++ function: virtual bool QObject::event(QEvent* event).

C++ documentation:

This virtual function receives events to an object and should return true if the event e was recognized and processed.

The event() function can be reimplemented to customize the behavior of an object.

Make sure you call the parent event class implementation for all the events you did not handle.

Example:

class MyClass : public QWidget { Q_OBJECT

public: MyClass(QWidget *parent = 0); ~MyClass();

bool event(QEvent* ev) { if (ev->type() == QEvent::PolishRequest) { // overwrite handling of PolishRequest if any doThings(); return true; } else if (ev->type() == QEvent::Show) { // complement handling of Show if any doThings2(); QWidget::event(ev); return true; } // Make sure the rest of events are handled return QWidget::event(ev); } };

See also installEventFilter(), timerEvent(), QCoreApplication::sendEvent(), and QCoreApplication::postEvent().

source

pub unsafe fn event_filter( &self, watched: impl CastInto<Ptr<QObject>>, event: impl CastInto<Ptr<QEvent>> ) -> bool

Filters events if this object has been installed as an event filter for the watched object.

Calls C++ function: virtual bool QObject::eventFilter(QObject* watched, QEvent* event).

C++ documentation:

Filters events if this object has been installed as an event filter for the watched object.

In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.

Example:

class MainWindow : public QMainWindow { public: MainWindow();

protected: bool eventFilter(QObject obj, QEvent ev);

private: QTextEdit *textEdit; };

MainWindow::MainWindow() { textEdit = new QTextEdit; setCentralWidget(textEdit);

textEdit->installEventFilter(this); }

bool MainWindow::eventFilter(QObject obj, QEvent event) { if (obj == textEdit) { if (event->type() == QEvent::KeyPress) { QKeyEvent keyEvent = static_cast<QKeyEvent>(event); qDebug() << “Ate key press” << keyEvent->key(); return true; } else { return false; } } else { // pass the event on to the parent class return QMainWindow::eventFilter(obj, event); } }

Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.

Warning: If you delete the receiver object in this function, be sure to return true. Otherwise, Qt will forward the event to the deleted object and the program might crash.

See also installEventFilter().

source

pub unsafe fn find_child_q_object_2a( &self, a_name: impl CastInto<Ref<QString>>, options: QFlags<FindChildOption> ) -> QPtr<QObject>

Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

Calls C++ function: QObject* QObject::findChild<QObject*>(const QString& aName = …, QFlags<Qt::FindChildOption> options = …) const.

C++ documentation:

Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.

This example returns a child QPushButton of parentWidget named "button1", even if the button isn't a direct child of the parent:

QPushButton button = parentWidget->findChild<QPushButton >(“button1”);

This example returns a QListWidget child of parentWidget:

QListWidget list = parentWidget->findChild<QListWidget >();

This example returns a child QPushButton of parentWidget (its direct parent) named "button1":

QPushButton button = parentWidget->findChild<QPushButton >(“button1”, Qt::FindDirectChildrenOnly);

This example returns a QListWidget child of parentWidget, its direct parent:

QListWidget list = parentWidget->findChild<QListWidget >(QString(), Qt::FindDirectChildrenOnly);

See also findChildren().

source

pub unsafe fn find_child_q_object_1a( &self, a_name: impl CastInto<Ref<QString>> ) -> QPtr<QObject>

Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

Calls C++ function: QObject* QObject::findChild<QObject*>(const QString& aName = …) const.

C++ documentation:

Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.

This example returns a child QPushButton of parentWidget named "button1", even if the button isn't a direct child of the parent:

QPushButton button = parentWidget->findChild<QPushButton >(“button1”);

This example returns a QListWidget child of parentWidget:

QListWidget list = parentWidget->findChild<QListWidget >();

This example returns a child QPushButton of parentWidget (its direct parent) named "button1":

QPushButton button = parentWidget->findChild<QPushButton >(“button1”, Qt::FindDirectChildrenOnly);

This example returns a QListWidget child of parentWidget, its direct parent:

QListWidget list = parentWidget->findChild<QListWidget >(QString(), Qt::FindDirectChildrenOnly);

See also findChildren().

source

pub unsafe fn find_child_q_object_0a(&self) -> QPtr<QObject>

Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

Calls C++ function: QObject* QObject::findChild<QObject*>() const.

C++ documentation:

Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.

This example returns a child QPushButton of parentWidget named "button1", even if the button isn't a direct child of the parent:

QPushButton button = parentWidget->findChild<QPushButton >(“button1”);

This example returns a QListWidget child of parentWidget:

QListWidget list = parentWidget->findChild<QListWidget >();

This example returns a child QPushButton of parentWidget (its direct parent) named "button1":

QPushButton button = parentWidget->findChild<QPushButton >(“button1”, Qt::FindDirectChildrenOnly);

This example returns a QListWidget child of parentWidget, its direct parent:

QListWidget list = parentWidget->findChild<QListWidget >(QString(), Qt::FindDirectChildrenOnly);

See also findChildren().

source

pub unsafe fn find_children_q_object_q_string_q_flags_find_child_option( &self, a_name: impl CastInto<Ref<QString>>, options: QFlags<FindChildOption> ) -> CppBox<QListOfQObject>

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. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

Calls C++ function: QList<QObject*> QObject::findChildren<QObject*>(const QString& aName = …, QFlags<Qt::FindChildOption> options = …) const.

C++ documentation:

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. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

The following example shows how to find a list of child QWidgets of the specified parentWidget named widgetname:

QList<QWidget > widgets = parentWidget.findChildren<QWidget >(“widgetname”);

This example returns all QPushButtons that are children of parentWidget:

QList<QPushButton > allPButtons = parentWidget.findChildren<QPushButton >();

This example returns all QPushButtons that are immediate children of parentWidget:

QList<QPushButton > childButtons = parentWidget.findChildren<QPushButton >(QString(), Qt::FindDirectChildrenOnly);

See also findChild().

source

pub unsafe fn find_children_q_object_q_reg_exp_q_flags_find_child_option( &self, re: impl CastInto<Ref<QRegExp>>, options: QFlags<FindChildOption> ) -> CppBox<QListOfQObject>

This function overloads findChildren().

Calls C++ function: QList<QObject*> QObject::findChildren<QObject*>(const QRegExp& re, QFlags<Qt::FindChildOption> options = …) const.

C++ documentation:

This function overloads findChildren().

Returns the children of this object that can be cast to type T and that have names matching the regular expression regExp, or an empty list if there are no such objects. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

source

pub unsafe fn find_children_q_object_q_regular_expression_q_flags_find_child_option( &self, re: impl CastInto<Ref<QRegularExpression>>, options: QFlags<FindChildOption> ) -> CppBox<QListOfQObject>

This function overloads findChildren().

Calls C++ function: QList<QObject*> QObject::findChildren<QObject*>(const QRegularExpression& re, QFlags<Qt::FindChildOption> options = …) const.

C++ documentation:

This function overloads findChildren().

Returns the children of this object that can be cast to type T and that have names matching the regular expression re, or an empty list if there are no such objects. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

This function was introduced in Qt 5.0.

source

pub unsafe fn find_children_q_object_q_string( &self, a_name: impl CastInto<Ref<QString>> ) -> CppBox<QListOfQObject>

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. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

Calls C++ function: QList<QObject*> QObject::findChildren<QObject*>(const QString& aName = …) const.

C++ documentation:

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. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

The following example shows how to find a list of child QWidgets of the specified parentWidget named widgetname:

QList<QWidget > widgets = parentWidget.findChildren<QWidget >(“widgetname”);

This example returns all QPushButtons that are children of parentWidget:

QList<QPushButton > allPButtons = parentWidget.findChildren<QPushButton >();

This example returns all QPushButtons that are immediate children of parentWidget:

QList<QPushButton > childButtons = parentWidget.findChildren<QPushButton >(QString(), Qt::FindDirectChildrenOnly);

See also findChild().

source

pub unsafe fn find_children_q_object(&self) -> CppBox<QListOfQObject>

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. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

Calls C++ function: QList<QObject*> QObject::findChildren<QObject*>() const.

C++ documentation:

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. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

The following example shows how to find a list of child QWidgets of the specified parentWidget named widgetname:

QList<QWidget > widgets = parentWidget.findChildren<QWidget >(“widgetname”);

This example returns all QPushButtons that are children of parentWidget:

QList<QPushButton > allPButtons = parentWidget.findChildren<QPushButton >();

This example returns all QPushButtons that are immediate children of parentWidget:

QList<QPushButton > childButtons = parentWidget.findChildren<QPushButton >(QString(), Qt::FindDirectChildrenOnly);

See also findChild().

source

pub unsafe fn find_children_q_object_q_reg_exp( &self, re: impl CastInto<Ref<QRegExp>> ) -> CppBox<QListOfQObject>

This function overloads findChildren().

Calls C++ function: QList<QObject*> QObject::findChildren<QObject*>(const QRegExp& re) const.

C++ documentation:

This function overloads findChildren().

Returns the children of this object that can be cast to type T and that have names matching the regular expression regExp, or an empty list if there are no such objects. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

source

pub unsafe fn find_children_q_object_q_regular_expression( &self, re: impl CastInto<Ref<QRegularExpression>> ) -> CppBox<QListOfQObject>

This function overloads findChildren().

Calls C++ function: QList<QObject*> QObject::findChildren<QObject*>(const QRegularExpression& re) const.

C++ documentation:

This function overloads findChildren().

Returns the children of this object that can be cast to type T and that have names matching the regular expression re, or an empty list if there are no such objects. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.

This function was introduced in Qt 5.0.

source

pub unsafe fn inherits(&self, classname: *const i8) -> bool

Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.

Calls C++ function: bool QObject::inherits(const char* classname) const.

C++ documentation:

Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.

A class is considered to inherit itself.

Example:

QTimer *timer = new QTimer; // QTimer inherits QObject timer->inherits(“QTimer”); // returns true timer->inherits(“QObject”); // returns true timer->inherits(“QAbstractButton”); // returns false

// QVBoxLayout inherits QObject and QLayoutItem QVBoxLayout *layout = new QVBoxLayout; layout->inherits(“QObject”); // returns true layout->inherits(“QLayoutItem”); // returns true (even though QLayoutItem is not a QObject)

If you need to determine whether an object is an instance of a particular class for the purpose of casting it, consider using qobject_cast<Type *>(object) instead.

See also metaObject() and qobject_cast().

source

pub unsafe fn install_event_filter( &self, filter_obj: impl CastInto<Ptr<QObject>> )

Installs an event filter filterObj on this object. For example:

Calls C++ function: void QObject::installEventFilter(QObject* filterObj).

C++ documentation:

Installs an event filter filterObj on this object. For example:


  monitoredObj->installEventFilter(filterObj);

An event filter is an object that receives all events that are sent to this object. The filter can either stop the event or forward it to this object. The event filter filterObj receives events via its eventFilter() function. The eventFilter() function must return true if the event should be filtered, (i.e. stopped); otherwise it must return false.

If multiple event filters are installed on a single object, the filter that was installed last is activated first.

Here's a KeyPressEater class that eats the key presses of its monitored objects:

class KeyPressEater : public QObject { Q_OBJECT ...

protected: bool eventFilter(QObject obj, QEvent event); };

bool KeyPressEater::eventFilter(QObject obj, QEvent event) { if (event->type() == QEvent::KeyPress) { QKeyEvent keyEvent = static_cast<QKeyEvent >(event); qDebug(“Ate key press %d”, keyEvent->key()); return true; } else { // standard event processing return QObject::eventFilter(obj, event); } }

And here's how to install it on two widgets:

KeyPressEater keyPressEater = new KeyPressEater(this); QPushButton pushButton = new QPushButton(this); QListView *listView = new QListView(this);

pushButton->installEventFilter(keyPressEater); listView->installEventFilter(keyPressEater);

The QShortcut class, for example, uses this technique to intercept shortcut key presses.

Warning: If you delete the receiver object in your eventFilter() function, be sure to return true. If you return false, Qt sends the event to the deleted object and the program will crash.

Note that the filtering object must be in the same thread as this object. If filterObj is in a different thread, this function does nothing. If either filterObj or this object are moved to a different thread after calling this function, the event filter will not be called until both objects have the same thread affinity again (it is not removed).

See also removeEventFilter(), eventFilter(), and event().

source

pub unsafe fn is_widget_type(&self) -> bool

Returns true if the object is a widget; otherwise returns false.

Calls C++ function: bool QObject::isWidgetType() const.

C++ documentation:

Returns true if the object is a widget; otherwise returns false.

Calling this function is equivalent to calling inherits("QWidget"), except that it is much faster.

source

pub unsafe fn is_window_type(&self) -> bool

Returns true if the object is a window; otherwise returns false.

Calls C++ function: bool QObject::isWindowType() const.

C++ documentation:

Returns true if the object is a window; otherwise returns false.

Calling this function is equivalent to calling inherits("QWindow"), except that it is much faster.

source

pub unsafe fn kill_timer(&self, id: i32)

Kills the timer with timer identifier, id.

Calls C++ function: void QObject::killTimer(int id).

C++ documentation:

Kills the timer with timer identifier, id.

The timer identifier is returned by startTimer() when a timer event is started.

See also timerEvent() and startTimer().

source

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>

Returns a pointer to the meta-object of this object.

Calls C++ function: virtual const QMetaObject* QObject::metaObject() const.

C++ documentation:

Returns a pointer to the meta-object of this object.

A meta-object contains information about a class that inherits QObject, e.g. class name, superclass name, properties, signals and slots. Every QObject subclass that contains the Q_OBJECT macro will have a meta-object.

The meta-object information is required by the signal/slot connection mechanism and the property system. The inherits() function also makes use of the meta-object.

If you have no pointer to an actual object instance but still want to access the meta-object of a class, you can use staticMetaObject.

Example:

QObject *obj = new QPushButton; obj->metaObject()->className(); // returns “QPushButton”

QPushButton::staticMetaObject.className(); // returns “QPushButton”

See also staticMetaObject.

source

pub unsafe fn move_to_thread(&self, thread: impl CastInto<Ptr<QThread>>)

Changes the thread affinity for this object and its children. The object cannot be moved if it has a parent. Event processing will continue in the targetThread.

Calls C++ function: void QObject::moveToThread(QThread* thread).

C++ documentation:

Changes the thread affinity for this object and its children. The object cannot be moved if it has a parent. Event processing will continue in the targetThread.

To move an object to the main thread, use QApplication::instance() to retrieve a pointer to the current application, and then use QApplication::thread() to retrieve the thread in which the application lives. For example:

myObject->moveToThread(QApplication::instance()->thread());

If targetThread is zero, all event processing for this object and its children stops.

Note that all active timers for the object will be reset. The timers are first stopped in the current thread and restarted (with the same interval) in the targetThread. As a result, constantly moving an object between threads can postpone timer events indefinitely.

A QEvent::ThreadChange event is sent to this object just before the thread affinity is changed. You can handle this event to perform any special processing. Note that any new events that are posted to this object will be handled in the targetThread.

Warning: This function is not thread-safe; the current thread must be same as the current thread affinity. In other words, this function can only "push" an object from the current thread to another thread, it cannot "pull" an object from any arbitrary thread to the current thread.

See also thread().

source

pub unsafe fn object_name(&self) -> CppBox<QString>

This property holds the name of this object

Calls C++ function: QString QObject::objectName() const.

C++ documentation:

This property holds the name of this object

You can find an object by name (and type) using findChild(). You can find a set of objects with findChildren().

qDebug(“MyClass::setPrecision(): (%s) invalid precision %f”, qPrintable(objectName()), newPrecision);

By default, this property contains an empty string.

Access functions:

QString objectName() const
void setObjectName(const QString &name)

Notifier signal:

void objectNameChanged(const QString &objectName)[see note below]

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

See also metaObject() and QMetaObject::className().

source

pub unsafe fn parent(&self) -> QPtr<QObject>

Returns a pointer to the parent object.

Calls C++ function: QObject* QObject::parent() const.

C++ documentation:

Returns a pointer to the parent object.

See also setParent() and children().

source

pub unsafe fn property(&self, name: *const i8) -> CppBox<QVariant>

Returns the value of the object's name property.

Calls C++ function: QVariant QObject::property(const char* name) const.

C++ documentation:

Returns the value of the object’s name property.

If no such property exists, the returned variant is invalid.

Information about all available properties is provided through the metaObject() and dynamicPropertyNames().

See also setProperty(), QVariant::isValid(), metaObject(), and dynamicPropertyNames().

source

pub unsafe fn qt_metacall( &self, arg1: Call, arg2: i32, arg3: *mut *mut c_void ) -> i32

Calls C++ function: virtual int QObject::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

source

pub unsafe fn qt_metacast(&self, arg1: *const i8) -> *mut c_void

Calls C++ function: virtual void* QObject::qt_metacast(const char* arg1).

source

pub unsafe fn remove_event_filter(&self, obj: impl CastInto<Ptr<QObject>>)

Removes an event filter object obj from this object. The request is ignored if such an event filter has not been installed.

Calls C++ function: void QObject::removeEventFilter(QObject* obj).

C++ documentation:

Removes an event filter object obj from this object. The request is ignored if such an event filter has not been installed.

All event filters for this object are automatically removed when this object is destroyed.

It is always safe to remove an event filter, even during event filter activation (i.e. from the eventFilter() function).

See also installEventFilter(), eventFilter(), and event().

source

pub unsafe fn set_object_name(&self, name: impl CastInto<Ref<QString>>)

This property holds the name of this object

Calls C++ function: void QObject::setObjectName(const QString& name).

C++ documentation:

This property holds the name of this object

You can find an object by name (and type) using findChild(). You can find a set of objects with findChildren().

qDebug(“MyClass::setPrecision(): (%s) invalid precision %f”, qPrintable(objectName()), newPrecision);

By default, this property contains an empty string.

Access functions:

QString objectName() const
void setObjectName(const QString &name)

Notifier signal:

void objectNameChanged(const QString &objectName)[see note below]

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

See also metaObject() and QMetaObject::className().

source

pub unsafe fn set_parent(&self, parent: impl CastInto<Ptr<QObject>>)

Makes the object a child of parent.

Calls C++ function: void QObject::setParent(QObject* parent).

C++ documentation:

Makes the object a child of parent.

See also parent() and children().

source

pub unsafe fn set_property( &self, name: *const i8, value: impl CastInto<Ref<QVariant>> ) -> bool

Sets the value of the object's name property to value.

Calls C++ function: bool QObject::setProperty(const char* name, const QVariant& value).

C++ documentation:

Sets the value of the object’s name property to value.

If the property is defined in the class using Q_PROPERTY then true is returned on success and false otherwise. If the property is not defined using Q_PROPERTY, and therefore not listed in the meta-object, it is added as a dynamic property and false is returned.

Information about all available properties is provided through the metaObject() and dynamicPropertyNames().

Dynamic properties can be queried again using property() and can be removed by setting the property value to an invalid QVariant. Changing the value of a dynamic property causes a QDynamicPropertyChangeEvent to be sent to the object.

Note: Dynamic properties starting with "_q_" are reserved for internal purposes.

See also property(), metaObject(), dynamicPropertyNames(), and QMetaProperty::write().

source

pub unsafe fn signals_blocked(&self) -> bool

Returns true if signals are blocked; otherwise returns false.

Calls C++ function: bool QObject::signalsBlocked() const.

C++ documentation:

Returns true if signals are blocked; otherwise returns false.

Signals are not blocked by default.

See also blockSignals() and QSignalBlocker.

source

pub unsafe fn start_timer_2a(&self, interval: i32, timer_type: TimerType) -> i32

Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

Calls C++ function: int QObject::startTimer(int interval, Qt::TimerType timerType = …).

C++ documentation:

Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

A timer event will occur every interval milliseconds until killTimer() is called. If interval is 0, then the timer event occurs once every time there are no more window system events to process.

The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.

If multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated.

Example:

class MyObject : public QObject { Q_OBJECT

public: MyObject(QObject *parent = 0);

protected: void timerEvent(QTimerEvent *event); };

MyObject::MyObject(QObject *parent) : QObject(parent) { startTimer(50); // 50-millisecond timer startTimer(1000); // 1-second timer startTimer(60000); // 1-minute timer

using namespace std::chrono; startTimer(milliseconds(50)); startTimer(seconds(1)); startTimer(minutes(1));

// since C++14 we can use std::chrono::duration literals, e.g.: startTimer(100ms); startTimer(5s); startTimer(2min); startTimer(1h); }

void MyObject::timerEvent(QTimerEvent *event) { qDebug() << “Timer ID:” << event->timerId(); }

Note that QTimer's accuracy depends on the underlying operating system and hardware. The timerType argument allows you to customize the accuracy of the timer. See Qt::TimerType for information on the different timer types. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some.

The QTimer class provides a high-level programming interface with single-shot timers and timer signals instead of events. There is also a QBasicTimer class that is more lightweight than QTimer and less clumsy than using timer IDs directly.

See also timerEvent(), killTimer(), and QTimer::singleShot().

source

pub unsafe fn start_timer_1a(&self, interval: i32) -> i32

Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

Calls C++ function: int QObject::startTimer(int interval).

C++ documentation:

Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.

A timer event will occur every interval milliseconds until killTimer() is called. If interval is 0, then the timer event occurs once every time there are no more window system events to process.

The virtual timerEvent() function is called with the QTimerEvent event parameter class when a timer event occurs. Reimplement this function to get timer events.

If multiple timers are running, the QTimerEvent::timerId() can be used to find out which timer was activated.

Example:

class MyObject : public QObject { Q_OBJECT

public: MyObject(QObject *parent = 0);

protected: void timerEvent(QTimerEvent *event); };

MyObject::MyObject(QObject *parent) : QObject(parent) { startTimer(50); // 50-millisecond timer startTimer(1000); // 1-second timer startTimer(60000); // 1-minute timer

using namespace std::chrono; startTimer(milliseconds(50)); startTimer(seconds(1)); startTimer(minutes(1));

// since C++14 we can use std::chrono::duration literals, e.g.: startTimer(100ms); startTimer(5s); startTimer(2min); startTimer(1h); }

void MyObject::timerEvent(QTimerEvent *event) { qDebug() << “Timer ID:” << event->timerId(); }

Note that QTimer's accuracy depends on the underlying operating system and hardware. The timerType argument allows you to customize the accuracy of the timer. See Qt::TimerType for information on the different timer types. Most platforms support an accuracy of 20 milliseconds; some provide more. If Qt is unable to deliver the requested number of timer events, it will silently discard some.

The QTimer class provides a high-level programming interface with single-shot timers and timer signals instead of events. There is also a QBasicTimer class that is more lightweight than QTimer and less clumsy than using timer IDs directly.

See also timerEvent(), killTimer(), and QTimer::singleShot().

source

pub unsafe fn thread(&self) -> QPtr<QThread>

Returns the thread in which the object lives.

Calls C++ function: QThread* QObject::thread() const.

C++ documentation:

Returns the thread in which the object lives.

See also moveToThread().

Trait Implementations§

source§

impl CppDeletable for QOpenGLContext

source§

unsafe fn delete(&self)

Destroys the QOpenGLContext object.

Calls C++ function: virtual [destructor] void QOpenGLContext::~QOpenGLContext().

C++ documentation:

Destroys the QOpenGLContext object.

If this is the current context for the thread, doneCurrent() is also called.

source§

impl Deref for QOpenGLContext

source§

fn deref(&self) -> &QObject

Calls C++ function: QObject* static_cast<QObject*>(QOpenGLContext* ptr).

§

type Target = QObject

The resulting type after dereferencing.
source§

impl DynamicCast<QOpenGLContext> for QObject

source§

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QOpenGLContext>

Calls C++ function: QOpenGLContext* dynamic_cast<QOpenGLContext*>(QObject* ptr).

source§

impl StaticDowncast<QOpenGLContext> for QObject

source§

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QOpenGLContext>

Calls C++ function: QOpenGLContext* static_cast<QOpenGLContext*>(QObject* ptr).

source§

impl StaticUpcast<QObject> for QOpenGLContext

source§

unsafe fn static_upcast(ptr: Ptr<QOpenGLContext>) -> Ptr<QObject>

Calls C++ function: QObject* static_cast<QObject*>(QOpenGLContext* ptr).

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.