All signals and slots have a "void" return value. You cannot return anything that way.
What you should do is define your signal so that it takes a reference argument that a slot can fill:
// MyClass.h
{
Q_OBJECT
// ...
signals:
void mySignal( int & result );
};
// MyClass.cpp
int MyClass::someFunction()
{
int result = 0; // ALWAYS initialize in case the slot doesn't update "result"
emit mySignal( result );
if ( result != 0 )
{
// do something
}
}
// MyClass.h
class MyClass : public QObject
{
Q_OBJECT
// ...
signals:
void mySignal( int & result );
};
// MyClass.cpp
int MyClass::someFunction()
{
int result = 0; // ALWAYS initialize in case the slot doesn't update "result"
emit mySignal( result );
if ( result != 0 )
{
// do something
}
}
To copy to clipboard, switch view to plain text mode
This code assumes that there is only one slot that will be connected to the signal. If more than one slot is connected, and each can set "result" to something different, then the only value you will get is for the slot that was connected last since signals are handled by slots in the order in which they were connected.
Bookmarks