[Interest] sharing singleton instance between C++ and QML

Stefan Seefeld stefan at seefeld.name
Fri Oct 27 23:05:53 CEST 2023


Hi Uli,

thank you for sharing that document, that's indeed very helpful.
Following its examples, I was able to set up my singleton such that both
runtimes (C++, QML) would share the same instance.
Doing that I bumped into what I would consider a bug, probably in the MOC
infrastructure:
The example I used was

```
struct SingletonForeign
{
  Q_GADGET
  QML_FOREIGN(MySingleton)
  QML_SINGLETON
  QML_NAMED_ELEMENT(MySingleton)
public:
  static MySingleton *create(QQmlEngine *, QJSEngine *engine);
};
```

which works fine. Then I wanted to clean the code up a little more, and
removed the "public:", given that the above is a `struct`, so everything in
it is public anyhow. And that's where it stopped working !
I assume this is because the MOC isn't really aware of C++ semantics, and
for some reason really requires the "public" specifier to be there. Why
isn't the MOC using an actual compiler frontend to analyse these
declarations ?

Thanks,

-- 

      ...ich hab' noch einen Koffer in Berlin...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231027/7c8ff4b6/attachment.htm>


More information about the Interest mailing list