Skip to content

Need to be able to choose the parent when deriving from different bases #474

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

Closed
ahayzen-kdab opened this issue Mar 10, 2023 · 6 comments · Fixed by #513
Closed

Need to be able to choose the parent when deriving from different bases #474

ahayzen-kdab opened this issue Mar 10, 2023 · 6 comments · Fixed by #513
Labels
🤔 discussion Feedback welcome ⬆️ feature New feature or request

Comments

@ahayzen-kdab
Copy link
Collaborator

ahayzen-kdab commented Mar 10, 2023

Currently we assume that it'll be QObject* parent = nullptr, but for some Qt types (eg QQuickPaintedItem or QQuickItem) the parent is different.

We need to have a way in the cxx_qt::qobject macro to be able to specify a different parent other than QObject.

There seems to be these options

  • If we can assume all parent types will be a raw pointer then just have #[cxx_qt::qobject(base = "QQuickPaintedItem", parent = "QQuickItem"]
  • If we can't assume this then we might need something like #[cxx_qt::qobject(base = "QQuickPaintedItem", parent_ptr = "QQuickItem"] or #[cxx_qt::qobject(base = "QQuickPaintedItem", parent = "QQuickItem*", parent_default = "nullptr"]
  • Have a separate macro for items that aren't directly derived from QObject, eg have #[cxx_qt::qquickitem(base = "QQuickPaintedItem")] this then means that we can generate the different asserts and parent etc and it's clear to the developer which base the type is deriving from
@ahayzen-kdab ahayzen-kdab added ⬆️ feature New feature or request 🤔 discussion Feedback welcome labels Mar 10, 2023
@LeonMatthesKDAB
Copy link
Collaborator

Could this be fixed by specifying our own constructor API 🤔 : #339

Would be a more general solution to the problem, right?

@ahayzen-kdab
Copy link
Collaborator Author

Potentially 🤔

So we then might have to get the following things into the same constructor feature

  • Picking a different parent type
  • Triggering code in the context of C++ from the constructor
  • How do we represent that QObject* parent has a default value of nullptr ?
  • Adding more args to the constructor (what happens with QML here though?)

@ahayzen-kdab
Copy link
Collaborator Author

We could make Option<*mut T> mean that it is a pointer that defaults to nullptr, but slightly odd syntax 🤔

@ahayzen-kdab
Copy link
Collaborator Author

Or do we use an attribute? As this appears to be supported by Syn in PatType https://docs.rs/syn/2.0.12/syn/struct.PatType.html

fn construct(#[default = "nullptr"] parent: *mut QQuickItem)

ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Apr 5, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
@ahayzen-kdab
Copy link
Collaborator Author

I've created an experiment in #513 of using the attribute route for the parent as the constructor route is much more complex. This then allows you to choose a different parent then allowing you to create a QQuickPaintedItem in Rust with no C++ :-)

ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Apr 5, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Apr 5, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Apr 5, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue May 22, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue May 23, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
Be-ing pushed a commit to ahayzen-kdab/cxx-qt that referenced this issue May 23, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
@LeonMatthesKDAB
Copy link
Collaborator

Closing this in favor of #550

ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Jul 5, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Jul 5, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Jul 7, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Jul 12, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
ahayzen-kdab added a commit to ahayzen-kdab/cxx-qt that referenced this issue Jul 12, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes KDAB#474
Be-ing pushed a commit that referenced this issue Jul 12, 2023
This then allows you to create a QQuickItem such as a QQuickPaintedItem.

Closes #474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 discussion Feedback welcome ⬆️ feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants