Skip to content

cxx-qt-lib: Add two more QtLogging functions #1227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for `QMessageLogContext` and sending log messages to the Qt message handler.
- Serde support for further types: `QByteArray`, `QSet`, `QStringList`, `QVector`, `QUrl`
- Added `QEventLoop` to cxx-qt-lib-extras.
- Support for setting Qt log message patterns with `q_set_message_pattern` and formatting log messages ith `q_format_log_message`.

### Removed

Expand Down
4 changes: 3 additions & 1 deletion crates/cxx-qt-lib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ mod qvector;
pub use qvector::{QVector, QVectorElement};

mod qtlogging;
pub use qtlogging::{qt_message_output, QMessageLogContext, QtMsgType};
pub use qtlogging::{
q_format_log_message, q_set_message_pattern, qt_message_output, QMessageLogContext, QtMsgType,
};

#[cxx::bridge]
mod ffi {
Expand Down
17 changes: 16 additions & 1 deletion crates/cxx-qt-lib/src/core/qtlogging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ mod ffi {
/// Outputs a message in the Qt message handler.
fn qt_message_output(msgType: QtMsgType, context: &QMessageLogContext, string: &QString);

/// Generates a formatted string out of the type, context, str arguments.
#[cxx_name = "qFormatLogMessage"]
fn q_format_log_message(
msgType: QtMsgType,
context: &QMessageLogContext,
string: &QString,
) -> QString;

/// Changes the output of the default message handler.
///
/// # Safety
/// This function is marked as unsafe because it is not guaranteed to be thread-safe.
#[cxx_name = "qSetMessagePattern"]
unsafe fn q_set_message_pattern(pattern: &QString);

#[cxx_name = "qmessagelogcontext_line"]
#[doc(hidden)]
fn line(context: &QMessageLogContext) -> i32;
Expand Down Expand Up @@ -131,4 +146,4 @@ unsafe impl ExternType for QMessageLogContext<'_> {
}

use crate::const_assert;
pub use ffi::{qt_message_output, QtMsgType};
pub use ffi::{q_format_log_message, q_set_message_pattern, qt_message_output, QtMsgType};
Loading