[Interest] New connection syntax
Igor Mironchik
igor.mironchik at gmail.com
Tue Dec 16 10:41:35 CET 2014
Hi,
On Tue, 16 Dec 2014 10:49:53 +0300, Igor Mironchik
<igor.mironchik at gmail.com> wrote:
>
> I.e. I want to have, for example, next method in my widget:
>
> Something * addSomething( QObject * receiver, PointerToMemberFunction
> method );
>
I've answered on the second question by myself. And now I have next code
in my ToolBar class:
/*!
Creates a new action with the given \a icon. This
action is added to the end of the toolbar. The action's
QAction::triggered() signal is connected to \a
method in \a receiver.
*/
template <typename Func1>
inline QAction * addAction( const QIcon & icon,
const typename QtPrivate::FunctionPointer<Func1>::Object * receiver,
Func1 slot )
{
QAction * action = new QAction( icon, QString(), this );
QObject::connect( action, &QAction::triggered, receiver, slot );
addAction( action );
return action;
}
/*!
Creates a new action with the given \a icon. This
action is added to the end of the toolbar. The action's
QAction::triggered() signal is connected to \a
functor.
*/
template <typename Func1>
inline QAction * addAction( const QIcon & icon, Func1 functor )
{
QAction * action = new QAction( icon, QString(), this );
QObject::connect( action, &QAction::triggered, functor );
addAction( action );
return action;
}
And my question is: is it ok to use QtPrivate::FunctionPointer in my
classes?
--
Best Regards,
Igor Mironchik.
More information about the Interest
mailing list