[Qt-interest] How To: pass extra data to object slots from menu action signals?
kent williams
nkwmailinglists at gmail.com
Mon Feb 1 22:35:58 CET 2010
I am working on a program that dynamically adds and removes actions
from menus, based on adding and deleting objects in the user
interface.
This causes a problem in QT -- actions attached to a QMenu send a
triggered() signal, but that signal can only be connected to a slot in
my class with a similar signature, e.g. triggered() or triggered(bool
b).
I figured out that I could use a QSignalMapper to map triggered() from
a menu action to a slot that takes a single string argument. But what
I'd like to do is pass in two strings. In other words I have a
multilevel menu like this
File
Save
Type1
Object1
Object2
Type2
Object1-1
Object1-2
And I want to trigger this slot
void SaveSomething(Type, ObjectName);
What I'm asking is this: is there a way to have a Signal send more
information to an object?
The only thing I could figure out is to construct strings containing
both arguments, and then use QSignalMapper to map that Action to that
string.
Is there a better way?
More information about the Qt-interest-old
mailing list