Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: meaning of slot return value?

According to the documentation the return value from a slot doesn't mean anything.
Yet in the generated moc code I see that if a slot returns a value this value is used for something. Any idea what does it do?


Here's an example of what I'm talking about. this is taken from code generated by moc. 'message' is a slot that doesn't return anything and 'selectPart' is declared as returning int.

case 7: message((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; case 8: { int _r = selectPart((*reinterpret_cast< AppObject*(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])));     if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break; 
like image 452
shoosh Avatar asked Sep 22 '08 02:09

shoosh


People also ask

Can a Qt signal return a value?

E.g. adding them, forming a vector out of them, or returning the last one. The common wisdom (expressed in the Qt documentation [EDIT: as well as some answers to this question ]) is that no such thing is possible with Qt signals. So: according to the docs, this thing isn't possible.

What is a slot in Qt?

A slot is a function that is called in response to a particular signal. Qt's widgets have many pre-defined slots, but it is common practice to subclass widgets and add your own slots so that you can handle the signals that you are interested in.

How Qt signals and slots work?

The Qt signals/slots and property system are based on the ability to introspect the objects at runtime. Introspection means being able to list the methods and properties of an object and have all kinds of information about them such as the type of their arguments.

What is a slot in framework?

Slots: certain classes or methods that are defined in the framework, but are unimplemented (user must implement them), and. Hooks: certain unimplemented functional elements that user may or may not implement.


1 Answers

The return value is only useful if you want to call the slot as a normal member function:

class MyClass : public QObject {     Q_OBJECT public:     MyClass(QObject* parent);     void Something(); public Q_SLOTS:     int Other(); };

void MyClass::Something() { int res = this->Other(); ... } Edit: It seems that's not the only way the return value can be used, the QMetaObject::invokeMethod method can be used to call a slot and get a return value. Although it seems like it's a bit more complicated to do.

like image 109
Terence Simpson Avatar answered Sep 24 '22 14:09

Terence Simpson