QAbstractEventDispatcher Class
La clase QAbstractEventDispatcher proporciona una interfaz para gestionar la cola de eventos de Qt. Más...
| Cabecera: | #include <QAbstractEventDispatcher> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core)target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| Hereda: | QObject |
| Heredado por: |
- Lista de todos los miembros, incluidos los heredados
- Miembros obsoletos
- QAbstractEventDispatcher es parte de Clases de Eventos.
Tipos Públicos
| struct | TimerInfoV2 |
| Duration |
Funciones Públicas
| QAbstractEventDispatcher(QObject *parent = nullptr) | |
| virtual | ~QAbstractEventDispatcher() |
| bool | filterNativeEvent(const QByteArray &eventType, void *message, qintptr *result) |
| void | installNativeEventFilter(QAbstractNativeEventFilter *filterObj) |
| virtual void | interrupt() = 0 |
| virtual bool | processEvents(QEventLoop::ProcessEventsFlags flags) = 0 |
| virtual void | registerSocketNotifier(QSocketNotifier *notifier) = 0 |
(since 6.8) void | registerTimer(Qt::TimerId timerId, QAbstractEventDispatcher::Duration interval, Qt::TimerType timerType, QObject *object) |
| virtual void | registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object) = 0 |
(since 6.8) Qt::TimerId | registerTimer(QAbstractEventDispatcher::Duration interval, Qt::TimerType timerType, QObject *object) |
| virtual QList<QAbstractEventDispatcher::TimerInfo> | registeredTimers(QObject *object) const = 0 |
| virtual int | remainingTime(int timerId) = 0 |
| QAbstractEventDispatcher::Duration | remainingTime(Qt::TimerId timerId) const |
| void | removeNativeEventFilter(QAbstractNativeEventFilter *filter) |
(since 6.8) QList<QAbstractEventDispatcher::TimerInfoV2> | timersForObject(QObject *object) const |
| virtual void | unregisterSocketNotifier(QSocketNotifier *notifier) = 0 |
(since 6.8) bool | unregisterTimer(Qt::TimerId timerId) |
| virtual bool | unregisterTimer(int timerId) = 0 |
| virtual bool | unregisterTimers(QObject *object) = 0 |
| virtual void | wakeUp() = 0 |
Señales
| void | aboutToBlock() |
| void | awake() |
Miembros Públicos Estáticos
| QAbstractEventDispatcher * | instance(QThread *thread = nullptr) |
Descripción Detallada
Un despachador de eventos recibe eventos del sistema de ventanas y de otras fuentes. Luego los envía a la instancia QCoreApplication o QApplication para su procesamiento y entrega. QAbstractEventDispatcher provee control fino sobre la entrega de eventos.
Para un control simple del procesamiento de eventos utiliza QCoreApplication::processEvents().
Para un control más fino del bucle de eventos de la aplicación, llame a instance() y llame a las funciones del objeto QAbstractEventDispatcher que se devuelve. Si quieres usar tu propia instancia de QAbstractEventDispatcher o de una subclase de QAbstractEventDispatcher, debes instalarla con QCoreApplication::setEventDispatcher() o QThread::setEventDispatcher() antes de que se haya instalado un despachador de eventos por defecto.
El bucle de eventos principal se inicia llamando a QCoreApplication::exec(), y se detiene llamando a QCoreApplication::exit(). Los bucles de eventos locales pueden crearse utilizando QEventLoop.
Los programas que realizan operaciones largas pueden llamar a processEvents() con una combinación bitwise OR de varios valores QEventLoop::ProcessEventsFlag para controlar qué eventos deben ser enviados.
QAbstractEventDispatcher también permite la integración de un bucle de eventos externo con el bucle de eventos de Qt.
Ver también QEventLoop, QCoreApplication, y QThread.
Documentación de tipos de miembros
[alias] QAbstractEventDispatcher::Duration
Un tipo std::chrono::duration que se utiliza en varias API de esta clase. Este tipo existe para facilitar una posible transición a una granularidad superior o inferior.
En todas las plataformas actuales, es nanoseconds.
Documentación de funciones miembro
[explicit] QAbstractEventDispatcher::QAbstractEventDispatcher(QObject *parent = nullptr)
Construye un nuevo despachador de eventos con la dirección parent.
[virtual noexcept] QAbstractEventDispatcher::~QAbstractEventDispatcher()
Destruye el despachador de eventos.
[signal] void QAbstractEventDispatcher::aboutToBlock()
Esta señal se emite antes de que el bucle de eventos llame a una función que podría bloquearse.
Véase también awake().
[signal] void QAbstractEventDispatcher::awake()
Esta señal se emite después de que el bucle de eventos vuelve de una función que podría bloquearse.
Véase también wakeUp() y aboutToBlock().
bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, void *message, qintptr *result)
Envía message a través de los filtros de eventos que fueron establecidos por installNativeEventFilter(). Esta función devuelve true en cuanto un filtro de eventos devuelve true, y false en caso contrario para indicar que el procesamiento del evento debe continuar.
Las subclases de QAbstractEventDispatcher deben llamar a esta función para todos los mensajes recibidos del sistema para asegurar la compatibilidad con cualquier extensión que pueda ser utilizada en la aplicación. El tipo de evento eventType es específico del complemento de plataforma elegido en tiempo de ejecución, y puede utilizarse para asignar el mensaje al tipo correcto. El puntero result sólo se utiliza en Windows, y corresponde al puntero LRESULT.
Tenga en cuenta que el tipo de message depende de la plataforma. Véase QAbstractNativeEventFilter para más detalles.
Véase también installNativeEventFilter() y QAbstractNativeEventFilter::nativeEventFilter().
void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
Instala un filtro de eventos filterObj para todos los eventos nativos recibidos por la aplicación.
El filtro de eventos filterObj recibe eventos a través de su función nativeEventFilter(), que es llamada para todos los eventos recibidos por todos los hilos.
La función nativeEventFilter() debe devolver true si el evento debe ser filtrado, (en este caso, detenido). Debería devolver false para permitir que el procesamiento normal de Qt continúe: el evento nativo puede entonces ser traducido a un QEvent y manejado por el filtrado estándar de Qt event, por ejemplo QObject::installEventFilter().
Si se instalan varios filtros de eventos, se activa primero el filtro que se instaló en último lugar.
Nota: La función de filtro establecida aquí recibe mensajes nativos, es decir, structs MSG o XEvent.
Para obtener la máxima portabilidad, debería intentar utilizar siempre que sea posible objetos QEvent y QObject::installEventFilter().
Véase también QObject::installEventFilter().
[static] QAbstractEventDispatcher *QAbstractEventDispatcher::instance(QThread *thread = nullptr)
Devuelve un puntero al objeto despachador de eventos para el thread especificado. Si thread es nullptr, se utiliza el subproceso actual. Si no existe un despachador de eventos para el subproceso especificado, esta función devuelve nullptr.
Nota: Si Qt se construye sin soporte para hilos, el argumento thread se ignora.
[pure virtual] void QAbstractEventDispatcher::interrupt()
Interrumpe el envío de eventos. El despachador de eventos regresará de processEvents() tan pronto como sea posible.
[pure virtual] bool QAbstractEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags)
Procesa los eventos pendientes que coincidan con flags hasta que no haya más eventos que procesar. Devuelve true si se ha procesado un evento; en caso contrario devuelve false.
Esta función es especialmente útil si tiene una operación de larga duración, y desea mostrar su progreso sin permitir la entrada del usuario mediante el uso de la bandera QEventLoop::ExcludeUserInputEvents.
Si la bandera QEventLoop::WaitForMoreEvents está activada en flags, el comportamiento de esta función es el siguiente:
- Si hay eventos disponibles, esta función regresa después de procesarlos.
- Si no hay eventos disponibles, esta función esperará hasta que haya más y volverá después de procesar los nuevos eventos disponibles.
Si la bandera QEventLoop::WaitForMoreEvents no está establecida en flags, y no hay eventos disponibles, esta función regresará inmediatamente.
Nota: Esta función no procesa los eventos de forma continua; vuelve después de procesar todos los eventos disponibles.
[pure virtual] void QAbstractEventDispatcher::registerSocketNotifier(QSocketNotifier *notifier)
Registra notifier con el bucle de eventos. Las subclases deben implementar este método para vincular un notificador de socket a otro bucle de eventos.
[since 6.8] void QAbstractEventDispatcher::registerTimer(Qt::TimerId timerId, QAbstractEventDispatcher::Duration interval, Qt::TimerType timerType, QObject *object)
Registra un temporizador con las direcciones timerId, interval, y timerType especificadas para la dirección object.
Esta función se introdujo en Qt 6.8.
Véase también unregisterTimer() y timersForObject().
[pure virtual] void QAbstractEventDispatcher::registerTimer(int timerId, qint64 interval, Qt::TimerType timerType, QObject *object)
Registra un temporizador con las direcciones timerId, interval, y timerType especificadas para la dirección object.
[since 6.8] Qt::TimerId QAbstractEventDispatcher::registerTimer(QAbstractEventDispatcher::Duration interval, Qt::TimerType timerType, QObject *object)
Registra un temporizador con el interval especificado y timerType para el object dado y devuelve el id del temporizador.
Esta es una función sobrecargada.
Esta función se introdujo en Qt 6.8.
[pure virtual] QList<QAbstractEventDispatcher::TimerInfo> QAbstractEventDispatcher::registeredTimers(QObject *object) const
Devuelve una lista de temporizadores registrados para object. La estructura TimerInfo tiene los siguientes miembros: timerId, interval, y timerType.
Véase también Qt::TimerType.
[pure virtual] int QAbstractEventDispatcher::remainingTime(int timerId)
Devuelve el tiempo restante en milisegundos con el timerId dado . Si el temporizador está inactivo, el valor devuelto será -1. Si el temporizador está vencido, el valor devuelto será 0.
Véase también Qt::TimerType.
QAbstractEventDispatcher::Duration QAbstractEventDispatcher::remainingTime(Qt::TimerId timerId) const
Devuelve el tiempo restante del temporizador con la dirección timerId. Si el temporizador está inactivo, el valor devuelto será negativo. Si el temporizador está vencido, el valor devuelto será 0.
Véase también Qt::TimerType, registerTimer(), y unregisterTimer().
void QAbstractEventDispatcher::removeNativeEventFilter(QAbstractNativeEventFilter *filter)
Elimina el filtro de eventos filter de este objeto. La petición se ignora si no se ha instalado dicho filtro de eventos.
Todos los filtros de eventos para este objeto se eliminan automáticamente cuando se destruye este objeto.
Siempre es seguro eliminar un filtro de eventos, incluso durante la activación del filtro de eventos (es decir, incluso desde dentro de la función nativeEventFilter()).
Véase también installNativeEventFilter() y QAbstractNativeEventFilter.
[since 6.8] QList<QAbstractEventDispatcher::TimerInfoV2> QAbstractEventDispatcher::timersForObject(QObject *object) const
Devuelve una lista de temporizadores registrados para object. La estructura TimerInfoV2 tiene los miembros timerId, interval, y timerType.
Esta función se introdujo en Qt 6.8.
Ver también Qt::TimerType, registerTimer(), y unregisterTimer().
[pure virtual] void QAbstractEventDispatcher::unregisterSocketNotifier(QSocketNotifier *notifier)
Desregistra notifier del despachador de eventos. Las subclases deben reimplementar este método para vincular un notificador de socket a otro bucle de eventos. Las reimplementaciones deben llamar a la implementación base.
[since 6.8] bool QAbstractEventDispatcher::unregisterTimer(Qt::TimerId timerId)
Desregistra el temporizador con la dirección timerId. Devuelve true si tiene éxito; en caso contrario devuelve false.
Esta función se introdujo en Qt 6.8.
Véase también registerTimer() y unregisterTimers().
[pure virtual] bool QAbstractEventDispatcher::unregisterTimer(int timerId)
Desregistra el temporizador con la dirección timerId. Devuelve true si tiene éxito; en caso contrario devuelve false.
Véase también registerTimer() y unregisterTimers().
[pure virtual] bool QAbstractEventDispatcher::unregisterTimers(QObject *object)
Elimina todos los temporizadores asociados a la dirección object. Devuelve true si todos los temporizadores se han eliminado correctamente; en caso contrario devuelve false.
Véase también unregisterTimer() y registeredTimers().
[pure virtual] void QAbstractEventDispatcher::wakeUp()
Activa el bucle de eventos.
Nota: Esta función es thread-safe.
Véase también awake().
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.