1

I have some data types defined as enum in a namespace.

I wanted to use Q_PROPERTY, that would return the data types...

But I get error:

'staticMetaObject' is not a member of 'blah'

So it seems, if I want to create my own types, and use them in functions that are mentioned in Q_PROPERTY, they must be inside a class inheriting QObject and declaring the Q_OBJECT macro ? Isn't that a lot of overhead ?

is there an alternative ?

Thalia
  • 13,637
  • 22
  • 96
  • 190
  • *So it seems, if I want to create my own types, and use them in functions that are mentioned in Q_PROPERTY, they must be inside a class inheriting QObject and declaring the Q_OBJECT macro ? Isn't that a lot of overhead ?* Can you please elaborate on that? What types? Which functions? Can you paste some code, possibly a SSSCE? – peppe Feb 19 '16 at 19:05

1 Answers1

3

Maybe you are searching for Q_GADGET? It generates metadata for non QObject derived types. You can have Q_PROPERTY and Q_INVOKABLE within a gadget.

And yes, there is quite a lot of overhead, if you don't need QObject don't use it. It is like 160 bytes to begin with.

dtech
  • 47,916
  • 17
  • 112
  • 190
  • 1
    @Thalia "the overhead of changing the namespace to a class" If you don't instantiate the class, there won't be any overhead. – Kuba hasn't forgotten Monica Feb 19 '16 at 18:56
  • @KubaOber Thank you that is very helpful. Does that also apply to a class with only static methods ? – Thalia Feb 22 '16 at 16:57
  • 1
    @Thalia Every instance must have a unique address, even if it's an empty class. So, if you instantiate even an empty class, there will be a little bit of memory allocated to it. If you only have static methods, there's no point in instantiating the class. Instead of calling via the instance, call via class name: prefer `Foo::method()` vs `Foo foo; foo.method()`. – Kuba hasn't forgotten Monica Feb 22 '16 at 17:06