Skip to content

Add bindings for QChar#1405

Open
jnbooth wants to merge 4 commits into
KDAB:mainfrom
jnbooth:qchar
Open

Add bindings for QChar#1405
jnbooth wants to merge 4 commits into
KDAB:mainfrom
jnbooth:qchar

Conversation

@jnbooth

@jnbooth jnbooth commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

A QString is a list of QChars, but cxx-qt-lib doesn't currently have bindings for QChar. That means any time you want to interact with the QString as a list (split, add, remove, etc.), you need to allocate a new QString. This PR adds bindings for QChar so it can be used directly. That also makes it much easier to find out what's inside a QString without needing to convert it to a String.

A QChar is just a standard UTF-16 double byte, so there's no need for FFI calls. In fact, they can be constructed at compile time. That means instead of doing this:

fn split_items(s: &QString) -> QStringList {
    s.split(&QString::from("|"), /* other args */)
}

You can now do this:

const DELIM: QChar = QChar::from_char('|').unwrap();

fn split_items(s: &QString) -> QStringList {
    s.split(DELIM, /* other args */)
}

This is both more efficient (no allocations) and more readable (no "magic" strings).

@codecov

codecov Bot commented Feb 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (061eaad) to head (9ab3415).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1405   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           75        75           
  Lines        13455     13455           
=========================================
  Hits         13455     13455           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


#[repr(C)]
#[derive(Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct QChar {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to add QChar as a test in qt_types_standalone as this does a round trip of construct, copy, destruct to check for memory leaks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants