graeme
29th May 2010, 06:53
I have a factory class which I want to use to create all of my objects. This currently works using Q_INVOKABLE with the constructor and then with a QMetaObject of the class I first check the constructorCount() assuming this is greater than zero for the class I wish to instantiate I then use newInstance()
All of this works and I can create the objects that I want to. However I would like to restrict the creation of these object to just the factory method and so I tried to make the constructor private. As soon as I do that the constructorCount() becomes zero. I have tried adding friendship to the class but with no success. This is what I have tried, where Factory is my class.
friend class Factory;
friend class QObject;
friend class QMetaObject;
friend class QMetaMethod;
Is there another class that I should be using or is this just not possible? (Maybe there is a inner class?)
All of this works and I can create the objects that I want to. However I would like to restrict the creation of these object to just the factory method and so I tried to make the constructor private. As soon as I do that the constructorCount() becomes zero. I have tried adding friendship to the class but with no success. This is what I have tried, where Factory is my class.
friend class Factory;
friend class QObject;
friend class QMetaObject;
friend class QMetaMethod;
Is there another class that I should be using or is this just not possible? (Maybe there is a inner class?)