0

I'm having a base class I derive from. That base class (BaseClass) is a pure c++ class (doesn't derive from QObject) and implements methods, which I'd like to provide to my QML interface without alteration.

Let's assume the base class implements a method bool foobar(). In my derived class (DerivedClass) I now wrap them like this:

DerivedClass.h:

class DerivedClass : public QObject, public Singleton<Phone>, public BaseClass {
  Q_OBJECT
  public:
    Q_INVOKABLE bool qt_foobar();

DerivedClass.cpp:

bool DerivedClass::qt_foobar() {
    return DerivedClass::instance().foobar();

That works perfectly fine, however I'm wondering whether there's a more elegant way to just pass or declare respective methods as Q_INVOKABLE without that wrapping and renaming.

Simon Warta
  • 10,850
  • 5
  • 40
  • 78
daten
  • 131
  • 1
  • 1
  • 12

1 Answers1

1

You can at least avoid having different names by calling BaseCass's implementation explicitly (as explained here) and do so directly in the header:

class DerivedClass : public QObject, public Singleton<Phone>, public BaseClass
{
    Q_OBJECT

    public:
        Q_INVOKABLE bool foobar() { return BaseClass::foobar() };

I never came across a way to register invokable methods to the MOC other than Q_INVOKABLE in front of a signature in a header.

Simon Warta
  • 10,850
  • 5
  • 40
  • 78