PDA

View Full Version : trying to use singleton pattern



therealjag
19th February 2006, 23:05
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

jacek
19th February 2006, 23:25
What did you change and what errors do you get?

therealjag
20th February 2006, 01:27
hey there im trying to do the following inside a tab class:


int multiply = demands->item(2,1)->data(Qt::DisplayRole).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...???

jacek
20th February 2006, 02:20
Singleton::instance() = multiply;
Usually Singleton::instance() returns a pointer or reference to Singleton instance, so you should use it like this:
Singleton::instance()->setValue( multiply );


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