direct slot invocation (Re: kdelibs/kdecore)

Antonio Larrosa Jiménez larrosa at kde.org
Sun Feb 16 22:40:59 GMT 2003


El Domingo, 16 de Febrero de 2003 20:23, Oswald Buddenhagen escribió:
> void KApplication::invokeEditSlot( const char *slot )
>
> > +{
> > +  QObject *object = focusWidget();
> > +
> >
> > +  if( !object || !slotName || !slot )
>
> if( !object )
>
> > +    return;
> > +
> > +  QMetaObject *meta = object->metaObject();
> >
> > +  QStrList l = meta->slotNames(true);
> > +
> > +  if( l.find( slotName ) == -1 )
> > +    return;
> > +
> > +  connect( this, SIGNAL( editSignal() ), object, slot );
> > +  emit editSignal();
> > +  disconnect( this, SIGNAL( editSignal() ), object, slot );
>
> int idx = meta->findSlot(slot, true);
> if (idx < 0)
>   return;
> object->qt_invoke(idx, 0);
>
> > +}
> > +
> >  void KApplication::addKipcEventMask(int id)
> >  {
> > @@ -1983,4 +2002,29 @@ void KApplication::invokeBrowser( const
> >        return;
> >     }
> > +}
> > +
> > +void KApplication::cut()
> > +{
> >
> > +  invokeEditSlot( "cut()", SLOT( cut() ) );
>
> invokeEditSlot( SLOT( cut() ) );

Sorry, I've not been following the thread, but isn't it better to use 
something along the lines of
KXMLGUIClient::action("edit_cut")->activate();  in the application code 
than hardwiring a slot name ( "cut()" ) in KApplication given that some 
applications may name it different ?

Of course, this doesn't work to invocate a "named slot" in a variable, but 
at least IMHO it's better than hardwiring slot names in KApplication for 
the above case.

Sorry if I'm out of topic. I'm really short of time lately to read all the 
threads.

Greetings,

--
Antonio Larrosa Jimenez
KDE developer - larrosa at kde.org
http://developer.kde.org/~larrosa/
Even a hawk is an eagle among crows.






More information about the kde-core-devel mailing list