Hi I coded this connection, but I need to do this: float type = setBox(int)); How? thanks
Qt Code:
connect(bgroup[i], SIGNAL(clicked(int)), this, SLOT(setBox(int)));To copy to clipboard, switch view to plain text mode
Hi I coded this connection, but I need to do this: float type = setBox(int)); How? thanks
Qt Code:
connect(bgroup[i], SIGNAL(clicked(int)), this, SLOT(setBox(int)));To copy to clipboard, switch view to plain text mode
Regards
Slots are just normal functions.
Delare your slot as
float setBox(int );
and then use as normal function whereever you want.
Mithin
www.mithin.in
sorry, I just declare it so. I need to do that connect and togheter assing its returned value to var type..........
Regards
Can you explain this ??I need to do that connect and togheter assing its returned value to var type..........
Mithin
www.mithin.in
that connect is right; it's works; but it return a float that I need to assign to a a variable;
I can't call setBox() is somewhere: it must return a value only when its signal occurs....
Regards
In that case your slot setBox(int) should emit a signal with your return value as a parameter and this signal will be connected to a slot in your bgroup[i].
I hope you understand what i mean.
Mithin
www.mithin.in
is there a way simpler? SLOT must be declared with a return value (eg void). I thought there's a sintax to assign its returned value to a variabile...
Last edited by mickey; 3rd June 2006 at 15:09.
Regards
Why? you must not declare return value ... on slot ...is possible to grab all data from GUI... if you set..Originally Posted by mickey
http://doc.trolltech.com/4.1/signalsandslots.html
Qt Code:
**.header --------------------- to call on emit method .... /* emits */ signals: void ConnectorSuccess(); void SendLine(); void ErrorCloseAll(); void SuccessQuit(); /* normal slot */ private slots: void disconnected(); void connected(); void ReadLiner(); void PutSendLine(); --------------------- linecmd = 34,56; /* save on class int .or float ... .. */ linesend = 8; /* save on class int .or float ... .. */ emit SendLine(); /* switsch all case.... or grab int or float direct from GUI */ void Smtp::PutSendLine() { int current = linesend; grab data ... linecmd qDebug() <<"### Go and Send line " << linesend; switch(current) { case 1: response = SendLineAndGrab("ehlo localhost"); if (response.size() > 0) { ErrorMSG.append(response); qDebug() << "1---- " << response; linesend = 2; emit SendLine(); } else { qDebug() << "Connection loost"; } response =""; break; case 2: response = SendLineAndGrab("AUTH LOGIN"); if (response.size() > 0) { ErrorMSG.append(response); qDebug() << "2---- " << response; linesend = 3; emit SendLine(); } else { qDebug() << "Connection loost"; } response =""; break; case 3: ....................... }To copy to clipboard, switch view to plain text mode
I'm still confused; can anyone learn me why QT permits to declare a SLOT in that way? (this compile). thanks
Qt Code:
public slots: float setBox(int);To copy to clipboard, switch view to plain text mode
Regards
It is allowed because slots are normal members functions... What allows connection is some extra meta-data (character strings with Qt meta object system) that is generated by moc and handled by signal/slots system. When a given signal is caught by event handlers all the connected slots (or signals as well BTW) are called one by one thus their return value can't be caught by the user... Emitting another signal is definitely the simplest way!
Current Qt projects : QCodeEdit, RotiDeCode
Sorry, I don' t still understand how use a signal...this is what i need do.....
How use signal; for what? thanksQt Code:
float setValBox(int i) { float ii; .......... return ii; } float type; connect(bgroup[i], SIGNAL(clicked(int)), this, SLOT(type=setValBox(int)));To copy to clipboard, switch view to plain text mode
Regards
signals are declared in headers that way :
signals are basically private function (or protected I'm not sure...) whose implementation is made by moc. You can call them just as normal functions but it's better to use the "emit" keyword before them to make it clear that they are signals... BTW "emit" is just an empty macro AFAIKQt Code:
{ Q_OBJECT signals: void mySignal( /*Place there the parameters as for a normal function*/ ); }To copy to clipboard, switch view to plain text mode
This code may look pretty ugly because I don't know exactly what you wanna do and how your classes interact...
Qt Code:
{ Q_OBJECT ... public slots: void setValBox(int val); private slots: void setValBox(float return); signals: void valBoxSet(float return); private: float returnValue; } ... X::X() { connect(bgroup[i], SIGNAL( clicked(int) ), this , SLOT ( setValBox(int) ); connect(this, SIGNAL( valBoxSet(float) ), this, SLOT ( setValBox(float) ); } void X::setValBox(int) { float ii; ... emit setValBox(ii); } void X::setValBox(float f) { returnValue = f; }To copy to clipboard, switch view to plain text mode
Current Qt projects : QCodeEdit, RotiDeCode
Hi, but for my aims this can be OK. The problem was that I don't want declare returnValue as class member, but only a local variabile........I hpe you understand my problem...
but what's diference between those:Originally Posted by fullmetalcoder
Qt Code:
void setValBox(float); void setValBox(float return);To copy to clipboard, switch view to plain text mode
Regards
A slot can't have a return value because you can attach multiple slots (=event-handlers) to the same signal (=event). Which one would Qt have to return? Besides, slots can run at a later time in the event queue, when your original function already ended.
It's recommended to find a different design that doesn't need return values. In your example, I'd rather use an interface:
First you have a base class that defines the interface all subclasses should confirm to.
Qt Code:
class BoxHandler { virtual float setBox(int) = 0; }To copy to clipboard, switch view to plain text mode
Then you can define multiple versions of your box function
Qt Code:
class BoxImplementation1 : public BoxHander { virtual float setBox(int); } class BoxImplementation2 : public BoxHander { virtual float setBox(int); }To copy to clipboard, switch view to plain text mode
And then code each method:
Qt Code:
float BoxImplementation1::setBox(int x) { ... } float BoxImplementation2::setBox(int x) { ... }To copy to clipboard, switch view to plain text mode
And the original class can use any reference, as long as it implements the BoxHandler interface:
The C++ runtime will automatically know whether it calls the first or second function:Qt Code:
void demo( BoxHandler *handler ) { float y = handler->setBox(x); }To copy to clipboard, switch view to plain text mode
Qt Code:
void caller() { BoxImplemtation2 handler; demo( handler ); }To copy to clipboard, switch view to plain text mode
Off course, the BoxImplementation classes may also be part of your normal classes:
Making the call something like:Qt Code:
... }To copy to clipboard, switch view to plain text mode
Qt Code:
void caller() { demo( myApplicationObject ); }To copy to clipboard, switch view to plain text mode
Last edited by vdboor; 4th June 2006 at 12:22.
Working on KMess, a MSN Messenger client for Linux/KDE.
Bookmarks