Results 1 to 2 of 2

Thread: Problem using Q_INVOKABLE on private constructor

  1. #1
    Join Date
    Jan 2006
    Posts
    40
    Thanks
    3
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem using Q_INVOKABLE on private constructor

    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?)
    Last edited by graeme; 29th May 2010 at 06:09.

  2. #2
    Join Date
    May 2010
    Posts
    24
    Thanked 8 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using Q_INVOKABLE on private constructor

    It seems you can't have an invokable private constructor (at least if you use the moc).

    Look at the generated moc_youfile.cpp, you'll see that when the constructor is private the free static function YourClass_qt_static_metacall doesn't contain the constructor call anymore or doesn't exist if it was the only invokable static method or slot.

Similar Threads

  1. Replies: 1
    Last Post: 22nd December 2009, 09:43
  2. private classes in QT
    By talk2amulya in forum Qt Programming
    Replies: 3
    Last Post: 19th February 2009, 17:26
  3. Constructor call problem
    By MarkoSan in forum Qt Programming
    Replies: 22
    Last Post: 28th May 2008, 14:04
  4. private inheritance
    By mickey in forum General Programming
    Replies: 8
    Last Post: 24th April 2008, 09:19
  5. Why does Qt use Private classes?
    By hyling in forum Qt Programming
    Replies: 2
    Last Post: 12th December 2006, 22:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.