0

can i use a slot with return ? for example :

QObject::connect(sender, SIGNAL(finished()), receiver, SLOT(onprocessFinished()));

and the pnprocessFinished return a QString that be used later that is possible? if yes how it must be done ?

Leo Chapiro
  • 13,678
  • 8
  • 61
  • 92
oumaimadev
  • 69
  • 7
  • That's a prime example for looking into the documentation. There exist many slots to get certain values upon specific "events"; it depends primarily on what QObject-derivation you talk about. That is, your question is not well-researched and, as is, too broad. – Sebastian Mach Nov 22 '13 at 10:08

1 Answers1

0

A slot can return a value, but the signal has to return the same type and it works for direct connection. You will get the returned value when you call emit:

void A::foo() {
    connect( this, SIGNAL(mySignal()), this, SLOT( mySlot() ) );
    int var = emit mySignal(); // int mySignal()
    qDebug() << var; // will print 12
}

int A::mySlot() {
    return 12;
}

But, I don't think that is useful...

Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37
  • There is a very good answer to this question here: http://stackoverflow.com/questions/5842124/can-qt-signals-return-a-value but one thing not addressed is cross thread signaling. Expecting a return value from a SIGNAL-SLOT connection assumes implementation details are function call semantics. In Cascades SIGNALS often cross threads and are actioned asynchronously. The fact that is works sounds like an artifact of the MOC compiler not a feature of the environment. – Richard Nov 24 '13 at 04:31