Chaining 2 connect statements



  • Hi everyone,
    I've been trying to connect 2 functions with signal and slots but i can't seem to do it that i've put as buttons.

    It is basically 2 parsing functions that i want to work in tandem but i can't seem to write a third connect statement that will join all of them together.
    connect(innerPage, SIGNAL(loadFinished(bool)), SLOT(parse(bool)));
    connect(innerPage2, SIGNAL(loadFinished(bool)), SLOT(parse2(bool)));

    I thought it would be simply
    connect(this,SIGNAL(parse(bool)),innerPage2,SLOT(on_pushButton_clicked());

    Can someone enlighten me?



  • hi @GCDX
    first, I'm guessing its a copy past error, but those two connect statements are wrong, they are missing a 4th parameter.

    connect(innerPage, SIGNAL(loadFinished(bool)), SLOT(parse(bool)));
    connect(innerPage2, SIGNAL(loadFinished(bool)), SLOT(parse2(bool)));

    I thought it would be simply
    connect(this,SIGNAL(parse(bool)),innerPage2,SLOT(on_pushButton_clicked());

    Can someone enlighten me?

    parse(bool) is obviously a SLOT, you connected to it as a slot previously, so you can't "listen" to the signal or connect to to it

    QObject::Connect allows the combination of SIGNAL -> SLOT, SIGNAL -> SIGNAL and since Qt5 and the new Syntax SIGNAL -> Any function, SIGNAL -> Lambda expression.

    But in all cases the origin has to be a defined QT-SIGNAL you cant connect 2 functions together.



  • @J-Hilk its not a copy paste error, it works, the lack of parameter put it to default this i think. So theres no solution to this???

    The idea i'm trying to achieve is, i need to access a webpage to parse some information and the parsed information is needed as arguments to access another webpage so that i can parse more information. Currently, this works with 2 buttons, one button to parse the first webpage and the second button when i want to parse more information from the next webpage.

    I was trying to automate it, but can't find a solution.



  • @GCDX
    you're right, theres actually a 3 parameter overload of connect

    bool QObject::connect(const QObject * sender, const char * signal, const char * method, Qt::ConnectionType type = Qt::AutoConnection) const
    

    Well, you can simply go the way of a custom signal, that you emit at the end of the parse(bool) slot, or since slots are basicaly functions, you can just call on_pushButton_clicked() at the end of parse



  • @J-Hilk silly me, that was the easiest solution did i didnt think about. Thanks!


Log in to reply
 

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