Skip to content
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

Add qobject extension trait #1226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BenFordTytherington
Copy link
Collaborator

@BenFordTytherington BenFordTytherington commented Mar 14, 2025

  • cxx-qt-lib trait for additional qobject wrappers

Closes #562

The added methods are:

  • blockSignals
  • signalsBlocked
  • setObjectName
  • objectName
  • parent
  • setParent

@BenFordTytherington BenFordTytherington force-pushed the add-qobject-extension branch 2 times, most recently from da2aeeb to 627a8a6 Compare March 14, 2025 12:03
Copy link

codecov bot commented Mar 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (64d4ee6) to head (0fc5b11).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1226   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           73        73           
  Lines        12612     12612           
=========================================
  Hits         12612     12612           

☔ 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.

@BenFordTytherington BenFordTytherington force-pushed the add-qobject-extension branch 6 times, most recently from e0c231e to 65f097a Compare March 14, 2025 13:13
@BenFordTytherington BenFordTytherington force-pushed the add-qobject-extension branch 4 times, most recently from 85550c4 to 0a3410d Compare March 28, 2025 15:24
@BenFordTytherington BenFordTytherington marked this pull request as ready for review March 28, 2025 15:58
Copy link
Collaborator

@LeonMatthesKDAB LeonMatthesKDAB left a comment

Choose a reason for hiding this comment

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

Some nitpicks, and some documentation is missing.

Otherwise looks good :)

//
// SPDX-License-Identifier: MIT OR Apache-2.0

use cxx_qt::QObject;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make this a pub use and add a cxx-qt-lib/qobject.h header that just includes the header from Qt.

This way we the import follows the usual pattern:

extern "C++" {
    include("cxx-qt-lib/qobject.h");
    type QObject = cxx_qt_lib::QObject;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This breaks an orphan rule, so I think it needs to just be the type def, which is what happens inside the cxx bridge in cxx_qt::QObject.

pub fn parent(self: &QObjectExternal) -> *mut QObjectExternal;

#[rust_name = "set_parent"]
pub unsafe fn setParent(self: Pin<&mut QObjectExternal>, parent: *mut QObjectExternal);
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to use parent: *mut QObject here and re-import the QObject from cxx_qt.

type QString = crate::QString;

#[rust_name = "block_signals"]
pub fn blockSignals(self: Pin<&mut QObjectExternal>, block: bool) -> bool;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: You can use the shorthand syntax self: Pin<&mut Self>/&self here if you move the QString import into a separate extern "C++" block.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also a good reminder that we don't support this in CXX-Qt yet...
I've opened an issue for it: #1245

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can fix once #1249 gets merged

- cxx-qt-lib trait for additional qobject wrappers
- adds blockSignals
- adds signalsBlocked
- adds setObjectName
- adds objectName
- adds parent
- adds setParent
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.

Traits for CxxQtType/QtObject
3 participants