Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, July 2007
Slots interface class


Message 1 in thread

Hi All!

Is there any possibility to create a slots interface class (like usual C++ 
interface class)? I mean following: in C++ we can create interface class, 
something like this:

class SomeInterface
{
public:
	virtual ~SomeInterface();
	
	virtual void Method1() = 0;
	virtual void ConstMethod1() const = 0;
	// ... so on
};

Is there any possibility to make something simmiliar for Qt slots?...

WBR,
Gleb Golubitsky AKA Sectoid.

--
 [ signature omitted ] 

Message 2 in thread

On 7/14/07, Sectoid <rush.william@xxxxxxxxx> wrote:
> Hi All!
>
> Is there any possibility to create a slots interface class (like usual C++
> interface class)? I mean following: in C++ we can create interface class,
> something like this:
>
> class SomeInterface
> {
> public:
>         virtual ~SomeInterface();
>
>         virtual void Method1() = 0;
>         virtual void ConstMethod1() const = 0;
>         // ... so on
> };
>
> Is there any possibility to make something simmiliar for Qt slots?...

Sort of. You can make an interface just like you described above, but
it is up to the implementer to remember the Q_OBJECT macro and to give
the method declarations the appropriate access specifier (i.e. "public
slots" instead of "public"). The same is true for signals - you can
declare the appropriate virtual functions in your interface class, but
you can't get the compiler to ensure that the implementer re-declares
them properly.

You can't have an interface class with true signals and slots because
classes can't inherit from QObject more than once. I think this (not
being able to define true signal/slot interface classes) is a
significant shortcoming, but that's just the way it is.

-- 
 [ signature omitted ]