Re: Slot gets called twice
If you're using the GUI designer you don't need to manually declare slots, you can get designer to create them for you from the object's context menu. (goto->slot)
Maybe delete your slots and re-create them with designer and see if you still have a problem.
Re: Slot gets called twice
your slot already connected in ui-file using QMetaObject::connectSlotsByName.
so, you should rename your slots or remove connections in designer.
Re: Slot gets called twice
thanks for your very quick response. But I am not sure i understand how to do this....
I don't think I have this context menu (goto->slot) in my 4.5.2 Designer (not in the VS Plugin and also not in 4.5.2 QtCreator either).
In my Designer if I view the Signals end slots editor I do not see any context menus [right-clcicking, from ny menu, etc].
In fact, if I look at http://www.qtcentre.org/forum/faq.ph..._signals_inqt4:
Quote:
How can I add a custom slot in Qt4 Designer? In short - you can't. Beginning with Qt4.0 Qt Designer seized to be an all-purpose development environment and became strictly a GUI Designer...etc
Can you be more specific...
Thankx
Re: Slot gets called twice
you wrote
Quote:
In QtDesigner I add a signal/slot to a QPushButton where the Sender is the QPushButton (signal is clicked()) and the Receiver a custom slot (called on_pbAdd_clicked()) on my form class derived form QDialog.
that means, that "on_pbAdd_clicked" default slot according to this, in ui-file you can find such call QMetaObject::connectSlotsByName (this will create first connection), than you have declared slot on_pbAdd_clicked and probably connected it in ctor (I'm not sure) in that case you created the second connection.
Re: Slot gets called twice
@spirit - thanks for your very prompt reply.
It seems to have done the trick!
But - just to make sure I understand: Does this imply that if you follow the the slot function naming convention of on_<objectname>_<signalname>(), then it is not necessary to define signal/slot combinations in the signal/slot editor of Designer since Qt can figure out which custom slot to call (which - as you imply - is done in the QMetaObject::connectSlotsByName() function)?
I've noticed that removing the connections in the signal/slot editor of Designer also removes the connections being generated by the moc previously:
Code:
{
...
QObject::connect(pbAdd,
SIGNAL(clicked
()), DialogClass,
SLOT(on_pbAdd_clicked
()));
QObject::connect(pbRemove,
SIGNAL(clicked
()), DialogClass,
SLOT(on_pbRemove_clicked
()));
...
}
Is this on_<objectname>_<signalname>() convention a kind of for custom slot generation as an alternative to the Designer route?
Thanx again [can see I still have lots to learn about Qt!]
Re: Slot gets called twice
all what you need it's to create a slot, but don't connect it, because it's already connected in ui. :)
Re: Slot gets called twice
Got it!
Thanks a stack @spirit!