QSignalWrapper uses wrong Method?
-
I'm coming right from Java (I was doing C++ years ago the last time...), so I assumed the Q*-Classes would all inherit from QObject. Now as I check it I see it's not like that.
As shown in the code I have the slot:
@ int addBtn(QIcon *icon = 0);@
I just want to trigger this event (Parameter included) as someone clicks another button.
How do I achieve that? -
Like I wrote before, a slot doesn't return anything.
To have something clean, you should rather have a parameterless slot where you will implement the button creation logic.
-
I know that a slot doesn't return anything, that's the reason why I used the QSignalMapper.
But I don't know how to use it with a QIcon -
You can't do it with QSignalMapper. If I understand correctly when you click on that button a new one should be created with an icon, then what should happen ?
-
So how can I do it? (Preferred not to subclass anything)
Nothing, that's all.
I just want to call the method addBtn(QIcon *icon) with the parameter if someone clicks a button.
-
Like I said, do it indirectly. Have a parameterless slot where you will create the button retrieving the icon has you need it.
-
That's the problem. I need to provide a Slot with a parameter. Otherwise I'd have done so already
-
What are the exact requirements ?
-
A slot with the parameter QIcon which creates a new Button with that QIcon and is called if you click something.
-
Directly, you can't have that. Qt's signals must be connected to slots with matching signatures or less (but still matching) parameters.
QSignalMapper works with either QString, QObjects, or QWidgets. So you can't have a slot with a QIcon * parameter. However and since there's chances that you build your icon using a path to an image file, you could use that to build your new button. But as i've stated before, your slots should not have any return type other than void.