2

I have a class with many private variables which I need to be able to modify with qspinboxes. I can do it by having a seperate slot for each variable connected to its particular spinbox but the code is getting lengthy and repetitive. I really want to have a single slot which takes the address of the variable to change and its new value. I think I could somehow use qsignalmapper for this but I can't figure out how. Can anyone help? -preferably with an example as I am a novice QT programmer. I am using Qt4 with C++ and Fedora 14

Richard
  • 21
  • 2
  • look here http://stackoverflow.com/questions/1883160/qsignalmapper-and-original-sender – Raiv Jan 13 '11 at 17:50

2 Answers2

0

What you most likely want to do is create a custom subclass of the spin box that can also keep track of 1 variable to modify. Create your custom subclass instead of the spin box, and for each spin box, pass the variable that it is supposed to be able to modify. Inside your custom class, you have one slot, which modifies the variable it knows about.

There are variations on this idea, but it is a simple way to reduce all of that repetition.

Caleb Huitt - cjhuitt
  • 14,785
  • 3
  • 42
  • 49
  • ARGH!, you beat me to it, my old nemesis cjhuitt. Do you know who I am? – Scott Jan 13 '11 at 21:26
  • @Scott: I could give a guess, if you've relocated to TX within the past couple of years. And if that's correct, you might know of a few instances of code that lead me to suggest the above solution. – Caleb Huitt - cjhuitt Jan 14 '11 at 16:18
  • Yup, that's me: Mr. Object Librarian. It was eerie seeing you post your answer when I was in the middle of formulating mine. Hope all is well! – Scott Jan 14 '11 at 16:32
0

Trust me, you'll want to slog it out and just have a bunch of repeated connect() lines, and member access functions. It's not that bad. QSignalMapper is meant for parameterless signals, and to relate them with integer ID's or pointers to QObjects. That's not your scenario.

Scott
  • 1,179
  • 7
  • 17