[Qt-interest] emit custom built objects in signal/slot

Ulf-Alexander v. Ceumern-Lindenstjerna ceumern at vrmagic.com
Tue Sep 15 16:32:30 CEST 2009


Sure.

Here is what I do:

class MyClass
{
	// declare stuff ...
};

Q_DECLARE_METATYPE(MyClass);


class OtherClass
{
signals:
	void stuffHappened(MyClass);
};

// some function
void stuff
{
	MyClass l_data;
	emit stuffHappened(l_data);
}

Works like a charm.

But now, as I think about it, what about l_data lifetime? Do I need to
make sure it exists long enough?

Regards, Ulf

> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Deepak Angeshwar
> Sent: Tuesday, September 15, 2009 2:52 PM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] emit custom built objects in signal/slot
> 
> All,
> 
> While using QTJambi I was able to pass only primitive-data-types or a
> java.lang.Object as the argument while emitting a value via the signal
> 
> Now I am evaluating QT 4.5 (using C++), is there a way to emit user
> defined C++ object?
> 
> If I try to extend a QObject in my C++ class and emit an object of
that
> class, I get the follwoing error.
> error: `QObject::QObject(const QObject&)' is private




More information about the Qt-interest-old mailing list