[Qt-interest] Passing a variable back from a form
Robert Wood
robert.wood at apostrophe.co.uk
Wed Mar 23 00:32:39 CET 2011
Hi and thanks for the reply. I don't understand how this would work. If
I connect the clicked signal to closed slot in the Signals/Slot editor,
it does close the dialogue down. What I am not clear is where the emit
would be put and also I don't follow how the calling form would receive
the value.
I have had a look at this:
http://doc.qt.nokia.com/latest/signalsandslots.html
After searching Google for Qt emit.
Also looked at various other pages that reference emit, but I can't
follow them and they seem different to my situation.
I need each button to return a different and unique value to the calling
form which the calling form will then use.
I probably have a blindness to this after spending several hours on it
so am maybe missing something obvious.
I've done this several times before with just one button closing the
form and sending a value back, but it's this whole thing of multiple
buttons closing the form and sending different values back that is
stumping me.
The pointer thing would work if I could make the passed pointer global
within the called dialogue or if I knew how to make that pointer
accessible to each of the buttons' slots.
Thanks again for your help. :~)
On 22/03/11 22:27, NoRulez wrote:
> 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
> _______________________________________________
> 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