Skip to content

Commit 7c5ef0b

Browse files
committed
cxx-qt-lib: Add two more QtLogging functions
This adds two new global functions available in <QtLogging>: qFormatLogMessage and qSetMessagePattern. qFormatLogMessage is similar to qt_message_output, but actually documented. Instead of going to the default message handler though, it outputs to a QString. This is probably not useful without message handler support, but it's easy to expose. qSetMessagePattern is very useful, as it allows CXX-Qt applications to set custom Qt message patterns for logging.
1 parent 3c6dbf1 commit 7c5ef0b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- `#[base = T]` is now suported in `extern "C++Qt"` blocks
3333
- Casting is automatically implmented for qobjects or types which have `#[base = T]` in `"RustQt"` or `"C++Qt"` blocks
3434
- Support for `QMessageLogContext` and sending log messages to the Qt message handler.
35+
- Support for setting Qt log message patterns with `set_message_pattern`.
3536

3637
### Removed
3738

crates/cxx-qt-lib/src/core/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ mod qvector;
110110
pub use qvector::{QVector, QVectorElement};
111111

112112
mod qtlogging;
113-
pub use qtlogging::{qt_message_output, QMessageLogContext, QtMsgType};
113+
pub use qtlogging::{
114+
format_log_message, qt_message_output, set_message_pattern, QMessageLogContext, QtMsgType,
115+
};
114116

115117
#[cxx::bridge]
116118
mod ffi {

crates/cxx-qt-lib/src/core/qtlogging.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ mod ffi {
3636
/// Outputs a message in the Qt message handler.
3737
fn qt_message_output(msgType: QtMsgType, context: &QMessageLogContext, string: &QString);
3838

39+
/// Generates a formatted string out of the type, context, str arguments.
40+
#[cxx_name = "qFormatLogMessage"]
41+
fn format_log_message(
42+
msgType: QtMsgType,
43+
context: &QMessageLogContext,
44+
string: &QString,
45+
) -> QString;
46+
47+
/// Generates a formatted string out of the type, context, str arguments.
48+
#[cxx_name = "qSetMessagePattern"]
49+
fn set_message_pattern(pattern: &QString);
50+
3951
#[cxx_name = "qmessagelogcontext_line"]
4052
#[doc(hidden)]
4153
fn line(context: &QMessageLogContext) -> i32;
@@ -131,4 +143,4 @@ unsafe impl ExternType for QMessageLogContext<'_> {
131143
}
132144

133145
use crate::const_assert;
134-
pub use ffi::{qt_message_output, QtMsgType};
146+
pub use ffi::{format_log_message, qt_message_output, set_message_pattern, QtMsgType};

0 commit comments

Comments
 (0)