Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: Problems accessing static member variable from static member function

  1. #21
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems accessing static member variable from static member function

    Hi,

    You can try a different solution.
    Let's see it is easy and safe also.

    class GetComboInstance
    {
    public:
    static GetComboInstance* createInstance();
    updateCombo();
    private:
    QComboBox *m_pComboBox;
    static GetComboInstance *m_pInstance;
    };

    In Cpp file:

    static GetComboInstance *GetComboInstance::m_pInstance = NULL;
    static GetComboInstance* GetComboInstance::createInstance()
    {
    if(m_pInstance == NULL)
    {
    m_pInstance = new GetComboInstance();
    }
    return m_pInstance;
    }

    now you can call updateCombo method on your instance of GetComboInstance class from any class. It is better and safe way.

  2. #22
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems accessing static member variable from static member function

    Please let me know what do you think
    Last edited by Sandip; 8th October 2008 at 13:47. Reason: updated contents

  3. #23
    Join Date
    Aug 2006
    Posts
    221
    Thanks
    3
    Thanked 29 Times in 19 Posts

    Default Re: Problems accessing static member variable from static member function

    I think that when you describe the singleton pattern, you should do it right, e.g. make constructors protected or private. ;-)

    http://www.inquiry.com/techtips/cpp_.../10min0200.asp

Similar Threads

  1. QPSQL problem
    By LoneWolf in forum Installation and Deployment
    Replies: 60
    Last Post: 4th November 2009, 14:22
  2. QPSQL driver in windows
    By brevleq in forum Installation and Deployment
    Replies: 31
    Last Post: 14th December 2007, 12:57
  3. how to add static library into qmake
    By Namrata in forum Qt Tools
    Replies: 1
    Last Post: 20th November 2007, 17:33
  4. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  5. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52

Tags for this Thread

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.