The question has two parts:
- Reaching a custom meta object without a default ctor implementation.
- Understanding why Qt defaults to Qt in this case.
Other respondents have already applied (2).
I want to contact (1).
I wrote a class, and I intend for users of this class to call ctor, which I wrote, which requires several arguments. However, due to requirements related to Qt, I have to add a constructor with a null argument.
This would make me happy to at least make the ctor with a null argument private, so that I could force the use of this ctor to be forbidden to all user code, EXCEPT the moc generated βmagicβ code.
Hello, happiness! It is possible.
You can really use friendships to make ctor private by default and still use Qt Metatype.
It looks something like this:
class MyClass { Q_GADGET Q_PROPERTY(QString text READ text) public: MyClass(QString text, bool sometruth, int someint); QString text() const { return text_; } private:
There are two ways to solve the problem of figuring out what to make friends.
You can mark ctor as private, try to recompile and parse the compiler error to find out what other type is trying to access the ctor of your class.
Or you can put assert(false); in the body of your ctor, create a binary file with debugging symbols (including Qt debugging symbols), and then look at the stack in the debugger when the statement fails. The stack will show the internal member function of Qt or the free function that called in your ctor. Friend, whatever this subscriber is.
This last method (using a debugger) works for me. (I was not fluent enough in the compiler to determine what type of output of the giant compiler error was what I needed to add as my friend.)