Results 1 to 4 of 4

Thread: trying to use singleton pattern

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question trying to use singleton pattern

    hey there, ive copied the singleton code from this thread(http://www.qtcentre.org/forum/showthread.php?t=465) and made a header file for it. now how do i use it to set it equal to my ints so that i can create an array from it. basically i want to set the singeton instance equal to a number from the user but i keep getting errors when i try to set something equal to it. any help would be much aprreciated, thanks. Jag

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: trying to use singleton pattern

    What did you change and what errors do you get?

  3. #3
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: trying to use singleton pattern

    hey there im trying to do the following inside a tab class:


    int multiply = demands->item(2,1)->data(Qt:isplayRole).toInt();
    Singleton::instance() = multiply;

    ive made the header file singleton.h exactly the same as the example given in the thread and im trying to access it the way that he said but i get an error saying: 'Singleton' has not been declared and 'instance' undeclared...???

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: trying to use singleton pattern

    Quote Originally Posted by therealjag
    Singleton::instance() = multiply;
    Usually Singleton::instance() returns a pointer or reference to Singleton instance, so you should use it like this:
    Qt Code:
    1. Singleton::instance()->setValue( multiply );
    To copy to clipboard, switch view to plain text mode 

    i get an error saying: 'Singleton' has not been declared and 'instance' undeclared...???
    It looks like you forgot the #include directive.

Similar Threads

  1. Publish Subscriber Pattern in Qt
    By donglebob in forum Qt Programming
    Replies: 9
    Last Post: 26th June 2013, 16:01
  2. pattern
    By mickey in forum General Discussion
    Replies: 3
    Last Post: 14th February 2009, 17:12
  3. Changing the Text Pattern?
    By ashukla in forum Qt Programming
    Replies: 13
    Last Post: 29th December 2007, 11:10
  4. Singleton pattern - end in recursion
    By probine in forum General Programming
    Replies: 6
    Last Post: 29th March 2006, 13:08
  5. Qt, Databases & the DAO Pattern
    By Paul Drummond in forum Qt Programming
    Replies: 1
    Last Post: 22nd February 2006, 16:13

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.