| zoran404 (15) | |||
I have 9 pushbuttons with the same onclick event:
Dose anyone know how how I can put this in less number of lines? I also have an array of pointers to those buttons, but since it isn't in the scope of mainwindow construcor I had to put it in in statement in podesi() finction whic I call onclick in above code. Dose anyone know how I can do this in the constructor? | |||
|
|
|||
| Disch (8620) | |
|
Depending on the API you're using, you can usually map all button presses to the same function, then get the pushbutton's ID within that function to differentiate them. But it depends on what API you're using. | |
|
Last edited on
|
|
| zoran404 (15) | |||
|
I'm useing Qt. I made a button grop but I don't know how to add onclick event with it. And I have a meny bar with 2 options. One should be a drop down meny with for now only one option and the other one would just be like a push button with onclick event. Also any idea on how to shorten the sode is welcome. This is my code: I think you can quess how the rest of the code looks like...
| |||
|
|
|||
| Disch (8620) | |
| Unfortunately my knowledge of Qt's API is nonexistent, so I can't be of further help to you here. Sorry. I'll have to let someone else field this one. | |
|
|
|
| zoran404 (15) | |
| Anyone else knows how Qt works? | |
|
|
|
| Stewbond (1843) | |||
|
I use Qt quite a bit, but I don't think that you can shorten this. By definition, each "slot" is a function. So each time you assign a slot to a pushbutton, you are assigning an entire function to that pushbutton. While it's a good idea, you can't assign the same slot with a different argument or something to a pushbutton. Here's an example of a NumPad class that I made for a touchscreen. It has everything but the form generating the ui_numpad.h:
| |||
|
|
|||
| Stewbond (1843) | |
|
Actually I take it back, You can define arguments for slots, but you have to connect the signals manually (this means manually redoing a lot of the stuff that Qt Creator is automatically doing for you). http://doc.qt.digia.com/qt/signalsandslots.html To do this, I think the easiest way is to implement QSignalMapper. You'd have to map each pushbutton's signal to the slot. You'd be able to use a generic slot for this, but you'd be defining each signal separately in order to specify the argument for the slot, so I'm not sure if you're actually saving any typing by doing it this way. http://qt-project.org/doc/qt-4.8/qsignalmapper.html | |
|
|
|
| zoran404 (15) | |
|
Conecting each object seperatedly, I don't think that would help either. I quess I wont be being shortening this code, but nwm, I have better things to think about... | |
|
|
|