[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: signals and slots vs. virtual_hook (was [PATCH] KFileDialog
From:       Thiago Macieira <thiago () kde ! org>
Date:       2008-07-15 22:00:06
Message-ID: 200807151900.06664.thiago () kde ! org
[Download RAW message or body]


Leo Savernik wrote:
>Am Dienstag, 15. Juli 2008 schrieb Thiago Macieira:
>> Besides, my point is exactly that qt_metacall *is* the same as
>> virtual_hook. There's no need to involve signals here. Technically all
>> you needed to do was:
>>
>> void MiddleClass::publicFunction(bool b)
>> {
>>     void *args[] = { &b };
>>     int id = metaObject()->indexOfMethod("privateFunction(bool)");
>>     qt_metacall(QMetaObject::InvokeMetaMethod, id, args);
>> }
>
>Cool, I didn't know that! It's ugly, but it should still be faster than
> a slot invocation.

The above is what the invokeMethod() call does. It hides the gory details 
from you, but that's all.

You should use it because the above actually contains an error. It should 
have been:

	void *args[] = { 0, &b };

args[0] is used to hold the return value. (Put a variable there and 
qt_metacall will store the return value for you in it)

Note, however, that indexOfMethod takes a *normalised* name. The following 
will never work (will return -1):

	indexOfMethod("privateFunction( bool )");
	indexOfMethod("privateFunction(const QString&)");
	indexOfMethod("privateFunction(char const *)");

Using invokeMethod hides the normalisation process from you and also 
provides a modicum of type safety.

>[Declaration]
>
>> protected:
>>     Q_INVOKABLE void privateFunction(bool b);
>> };
>
>Say, I don't have a Q_INVOKABLE in release x. Is then adding Q_INVOKABLE
> in release x+1 BIC?

That's a binary- and source-compatible change. Unlike the virtual table, 
the meta object searches entries by string comparison -- the 
indexOfMethod call above. So you can add and remove as many entries as 
you want.

Also, note that setting the method to Q_SCRIPTABLE or making it a slot 
makes it invokable too. (Slots can be scriptable too)

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

["signature.asc" (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic