[Qt-interest] Passing a variable back from a form
NoRulez
norulez at me.com
Tue Mar 22 23:27:44 CET 2011
Hi,
you could connect the buttons to the dialogs close() slot and emit a signal with your value (e.g. emit buttonValue(42); )
Best Regards
Am 22.03.2011 um 23:12 schrieb Robert Wood <robert.wood at apostrophe.co.uk>:
> I am trying to create a pop-up window that has a load of JPEGs on it.
> When one of the JPEGs (which is put on a push button) is clicked, I want
> the form to close and a value dependent on which button is pressed
> passed back to the calling form.
>
> I have tried a few things such as making it a dialogue box, but this
> doesn't work as you seem to need to press the OK button. I tried this
> (using a naughty global variable!):
>
>
> // This routine does return the value and close the form
> quint16 config_dialogue::returnConfig(void)
> {
>
> return RetVal;
>
> }
>
> // This is one of the JPEG buttons; it does set the RetVal to 42
> // but it does not shut the form down and pass the value back
> quint16 config_dialogue::nineGroups(void)
> {
>
> RetVal = 42;
> returnConfig();
>
> }
>
> Then used this from the calling from:
>
> config_dialogue dialogue(this);
>
> if (dialogue.exec() == QDialog::Accepted)
> {
> ConfigNumber = dialogue.returnConfig();
> ui->label->setText("Number returned" + QString::number(ConfigNumber));
> }
>
> And although I do get 42 back. I still have to press the OK button.
>
> So, is there a way to have a load of buttons on a form and whichever
> button you press it passes a unique number back to the calling form
> please? It doesn't have to be a dialogue, just a normal form will be fine.
>
> I did try passing a pointer to a variable to the dialogue/form and
> making the dialogue modal, but the scope of it is only within the class
> constructor. I guess there might be a way of having this pointer
> accessible within the rest of the class, but this would be a weakness in
> my C++ knowledge. (Yes I know this isn't a C++ tutorial forum, so if
> this question offends please just ignore me!).
>
> Thanks!
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list