[Qt-interest] Stopping QAction from parsing "&"

Colin S. Miller no-spam-thank-you at csmiller.demon.co.uk
Thu Jun 10 22:14:05 CEST 2010


Nikos Chantziaras wrote:
> I have a QMenu where I add QActions using the
> 
>   QMenu::addAction(const QString& text)
> 
> function.  Problem is, 'text' contains filenames (you guessed it; it's 
> for a "Recent Files" menu), and some of the filenames contain "&" 
> characters.  This gets parsed and generates a shortcut.  That's wrong, 
> of course.  How do I prevent this from happening?

Nikos,
The standard was of doing this is to double the &.

Use myString.replace("&", "&&")

HTH,
Colin S. Miller




More information about the Qt-interest-old mailing list