Suppose I have some class that derives from QObject:

Qt Code:
  1. class MyTest : public QObject {
  2. Q_OBJECT
  3. // ...
  4. };
To copy to clipboard, switch view to plain text mode 

And I want to return pointer to this class from Q_INVOKABLE function, like this:
Qt Code:
  1. Q_INVOKABLE MyTest *createMyTest(){
  2. return new MyTest();
  3. }
To copy to clipboard, switch view to plain text mode 
However, when I try to invoke this method from the script in QJSEngine, I get the following error:
Qt Code:
  1. Error: Unknown method return type: MyTest*
To copy to clipboard, switch view to plain text mode 
If I make createMyTest() to return QObject* instead of MyTest*, it works. But of course this would force me to use casts, which I'd like to avoid. So, how to make it work with MyTest*?
Just by chance, I tried to declare metatype, as follows:
Qt Code:
  1. Q_DECLARE_METATYPE(MyTest*)
To copy to clipboard, switch view to plain text mode 
But this didn't help.
Thanks in advance.