Same signal in 2 functions



  • is it possible using the same signal in 2 functions?

    @
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function1(QString)));
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function2(QString)));
    @

    i tried it but the 2nd function hangs-up so i was thinking if i got it right or there is something missing in my code. i must not combine the 2 functions because i want the function1() available to any widget.

    @
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function1(QString)));
    connect(widget1, SIGNAL(currentTextChanged(QString)), this, SLOT(function2(QString)));
    connect(widget2, SIGNAL(currentTextChanged(QString)), this, SLOT(function1(QString)));
    connect(widget2, SIGNAL(currentTextChanged(QString)), this, SLOT(function3(QString)));
    @



  • You can connect one signal to multiple slots.

    Seems some different issue here, what is going on in 2nd function ?



  • the 2nd function / slot just display a QBoxMessage from 1st function

    @
    QLineEdit *val;
    function1(QString data) {
    QMessageBox::information(this, "msg", "hello"); // just an identifier if this is the first to be called.
    QString result = process(data); // just processing to return a string
    val = new QLineEdit();
    val->setText(result);
    }
    function2(QString data) {
    QMessageBox::information(this, "msg", "world"); // just an identifier if this is the second to be called.
    QMessageBox::information(this, "msg", val->text());
    }
    @



  • are you saying it didn't even show "world" dialog ?
    I'd suspect something went wrong in process(data) ....



  • i dont know if this is totally solved but my problem is fixed by changing the function type.

    before:
    @
    QString function1(QString data) {
    QString result = process(data); // just processing to return a string
    val = new QLineEdit();
    val->setText(result);
    return result;
    }
    @

    after:
    @
    void function1(QString data) {
    QString result = process(data); // just processing to return a string
    val = new QLineEdit();
    val->setText(result);
    }
    @

    i guess only void type is acceptable. correct me if i get it wrong.



  • yes. the "world" dialog didnt show.

    [quote author="chetankjain" date="1298614470"]are you saying it didn't even show "world" dialog ?
    I'd suspect something went wrong in process(data) ....[/quote]



  • [quote author="xeroblast" date="1298614555"]i guess only void type is acceptable. correct me if i get it wrong.[/quote]

    Not correct. The return type can be anything.

    Some inconsistency, in your earlier example you posted code for methods called function1 and function2 and in the most recent code snip its ... QString function1(..) and void function1(..)?



  • [quote author="chetankjain" date="1298614808"]
    Some inconsistency, in your earlier example you posted code for methods called function1 and function2 and in the most recent code snip its ... QString function1(..) and void function1(..)?
    [/quote]

    im sorry, i forgot to put the QString type in the function1() and function2() is a void in my previous code.



  • Still it does not make sense that why second function would hang.

    is it possible for u to paste complete code which hangs ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.