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

How to define multiple inheritance (i.e. QObject + another class) #678

Open
haata opened this issue Sep 1, 2023 · 1 comment
Open

How to define multiple inheritance (i.e. QObject + another class) #678

haata opened this issue Sep 1, 2023 · 1 comment
Labels
🤔 discussion Feedback welcome ⬆️ feature New feature or request

Comments

@haata
Copy link
Contributor

haata commented Sep 1, 2023

I'm still pouring over the source code to see if multiple inheritance is possible with the macros.

Trying to replicate this

  class OpenRGBSamplePlugin : public QObject, public OpenRGBPluginInterface
  {
      Q_OBJECT
      Q_PLUGIN_METADATA(IID OpenRGBPluginInterface_IID)
      Q_INTERFACES(OpenRGBPluginInterface)

This doesn't seem sufficient

    #[cxx_qt::qobject(base = "OpenRGBPluginInterface", qml_uri = "com.kdab.cxx_qt.demo", qml_version = "1.0")]
    #[derive(Default)]
    pub struct OpenRGBSamplePlugin {}
@ahayzen-kdab
Copy link
Collaborator

ahayzen-kdab commented Sep 4, 2023

Thanks for taking the time to report this issue.

With the current and the 0.6 API we don't yet support specifying

  • Multiple bases
  • Q_INTERFACES
  • Q_PLUGIN_METADATA

The way to workaround this for now would be to create a C++ class that has both the base classes and the metadata you can't specify in CXX-Qt yet. Then inherit from that combined C++ class in Rust.

class OpenRGBSampleCombined : public QObject, public OpenRGBPluginInterface
{
      Q_OBJECT
      Q_PLUGIN_METADATA(IID OpenRGBPluginInterface_IID)
      Q_INTERFACES(OpenRGBPluginInterface)
...
};

Then in Rust inherit from that C++ class

   unsafe extern "C++" {
        include!("cpp/combinedheader.h");
    }

    #[cxx_qt::qobject(base = "OpenRGBSampleCombined", qml_uri = "com.kdab.cxx_qt.demo", qml_version = "1.0")]
    #[derive(Default)]
    pub struct OpenRGBSamplePlugin {}

or for 0.6 something like

unsafe extern "C++" {
    include!("cpp/combinedheader.h");
}

extern "RustQt" {
    #[qobject] 
    #[qml_element]
    #[base_class = "OpenRGBSampleCombined"]
    type OpenRGBSamplePlugin = super::OpenRGBSamplePluginRust;
}

@LeonMatthesKDAB we should consider if we want to support things like Q_INTERFACES https://doc.qt.io/qt-6/qobject.html#Q_INTERFACES and Q_PLUGIN_METADATA https://doc.qt.io/qt-6/qtplugin.html#Q_PLUGIN_METADATA and multiple bases etc

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

No branches or pull requests

2 participants