Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtMultimediaPrivate::QMessageSpy Class Reference

#include <qmessagespy_p.h>

Collaboration diagram for QtMultimediaPrivate::QMessageSpy:

Classes

class  WaitToken

Public Member Functions

 QMessageSpy (const QLoggingCategory &category)
 QMessageSpy (QLatin1StringView category={})
 ~QMessageSpy ()
WaitToken expect (QtMsgType type, const QString &message)
 Register an expectation for a message of type matching message exactly.
WaitToken expect (QtMsgType type, const QRegularExpression &pattern)
 Register an expectation for a message of type matching pattern.

Detailed Description

QMessageSpy intercepts Qt logging messages via qInstallMessageHandler. Messages matching a pending expect() are silently consumed; all other messages are forwarded to the previous handler (e.g. QTest's default).

Usage:

// Register expectation BEFORE triggering the message:
auto token = spy.expect(QtDebugMsg, "expected message");
triggerCodeThatLogs();
QVERIFY(token.wait());
// Regex variant:
auto token2 = spy.expect(QtWarningMsg, QRegularExpression("file: .*\\.wav"));
triggerCode();
QVERIFY(token2.wait(2000ms));
\inmodule QtCore \reentrant
QMessageSpy(const QLoggingCategory &category)
QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)))
[0]
Token token
Definition keywords.cpp:452
@ QtWarningMsg
Definition qlogging.h:33
@ QtDebugMsg
Definition qlogging.h:31
#define QVERIFY(statement)
Definition qtestcase.h:65

Multiple waiters are supported simultaneously.

Definition at line 103 of file qmessagespy_p.h.

Constructor & Destructor Documentation

◆ QMessageSpy() [1/2]

QtMultimediaPrivate::QMessageSpy::QMessageSpy ( const QLoggingCategory & category)
inlineexplicit

Definition at line 145 of file qmessagespy_p.h.

◆ QMessageSpy() [2/2]

QtMultimediaPrivate::QMessageSpy::QMessageSpy ( QLatin1StringView category = {})
inlineexplicit

Definition at line 150 of file qmessagespy_p.h.

◆ ~QMessageSpy()

QtMultimediaPrivate::QMessageSpy::~QMessageSpy ( )
inline

Definition at line 160 of file qmessagespy_p.h.

Member Function Documentation

◆ expect() [1/2]

WaitToken QtMultimediaPrivate::QMessageSpy::expect ( QtMsgType type,
const QRegularExpression & pattern )
inlinenodiscard

Register an expectation for a message of type matching pattern.

Definition at line 185 of file qmessagespy_p.h.

◆ expect() [2/2]

WaitToken QtMultimediaPrivate::QMessageSpy::expect ( QtMsgType type,
const QString & message )
inlinenodiscard

Register an expectation for a message of type matching message exactly.

Returns a WaitToken; call wait() on it after triggering the message. The matching message is consumed (not forwarded to the previous handler).

Definition at line 172 of file qmessagespy_p.h.


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