[Qt-interest] Dynamic QMenuBar - passing a value to the slot inconnect( )?

Robert Wood robert.wood at apostrophe.co.uk
Thu Mar 24 20:28:53 CET 2011


Thanks, I'm sure that is part of it all having singularly failed to get 
the QSignalMapper working.

This is too complex for me, I'll go back to how I did it before with a 
drop down box...that's really straightforward! Not quite as 
aesthetically pleasing, but this is only for a piece of software that 
one or two people will ever use as part of a test procedure.

On 24/03/11 19:12, Chris Vickery wrote:
> Additionally, and unrelated to your question: I don't know if this is
> psuedocode, or if "numberOfEntries" is a define, but assuming neither
> of those,
> QAction *exitAction[numberOfEntries];
> isn't valid. You can't have dynamic sized arrays on the stack, you
> need to use a QAction**, QList<QAction*>, or something similar
>
> Hopefully that saves you some future headache...
>
> On Thu, Mar 24, 2011 at 2:58 PM, Scott Aron Bloom
> <Scott.Bloom at onshorecs.com>  wrote:
>> Look at QSignalMapper.. it will help you do exactly what you are looking
>> for
>>
>> -----Original Message-----
>> From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
>> [mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
>> Behalf Of Robert Wood
>> Sent: Thursday, March 24, 2011 11:04 AM
>> To: qt-interest at qt.nokia.com
>> Subject: [Qt-interest] Dynamic QMenuBar - passing a value to the slot
>> inconnect( )?
>>
>> I have successfully created a QMenuBar on the fly according to the
>> number of com ports in my /dev directory. I have then managed to have
>> each entry in the menu call a routine. However, I cannot work out how to
>> pass the string of the selected item to the routine called. The code is
>> as below:
>>
>>
>> // In the routine that detects the VCPs:
>> // numberOfEntries is how many VCPs in the /dev directory // results is
>> a QStringList of the directory entires QAction
>> *exitAction[numberOfEntries];
>>
>> for (i=0;i<numberOfEntries;i++)
>>         {
>>         exitAction[i] =  ui->menuSelectPort->addAction(results.at(i));
>>         connect(exitAction[i], SIGNAL(triggered()), this,
>> SLOT(openPort()));
>>         }
>>
>>
>> This works in that any item elected in the menuSelectPort of the
>> QMenuBar calls the openPort routine.
>>
>> I have tried various things such as:
>>
>> connect(exitAction[i], SIGNAL(triggered()), this,
>> SLOT(openPort(results.at(i))));
>>
>> or even:
>>
>> connect(exitAction[i], SIGNAL(triggered()), this, SLOT(openPort(i)));
>>
>> (The latter just to try and prove a point.)
>>
>> And then having openPort setup so it expects a string or a number passed
>> to it, but this just doesn't work.
>>
>> So how can I make it so my dynamically created menu passes its string
>> from the menu item selected by the user to the slot it calls? The
>> obvious method doesn't work and in fact as soon as I try and pass
>> anything at all to openPort() it doesn't call the openPort routine at
>> all!
>>
>> Many 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