Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTableWidget add parameters to slot



  • Hello all

    I have a tablewidget and i want to add two parameters to itemClicked().
    The original Slot works fine:
    *.h

        void on_tbl_suche_itemClicked(QTableWidgetItem *item);
    
    

    *.cpp

    void MainWindow::on_tbl_suche_itemClicked(QTableWidgetItem *item){
        cout << "Hello" << endl;
    }
    

    But if I add parameters

    *.h

        void on_tbl_suche_itemClicked(QTableWidgetItem *item, Kurve kurve, Pumpe_o pumpe);
    
    

    *.cpp

    void MainWindow::on_tbl_suche_itemClicked(QTableWidgetItem *item, Kurve kurve, Pumpe_o pumpe){
        cout << "Hello" << endl;
    }
    

    I receive the error message

    QMetaObject::connectSlotsByName: No matching signal for on_tbl_suche_itemClicked(QTableWidgetItem*,Kurve,Pumpe_o)
    

    How can I make the signal/slot work with additional parameters?

    Thanks in advance
    Thomas



  • @Thomas-63
    At present you seem to be using the "auto-connect" feature from Qt Designer of naming your slot on_tbl_suche_itemClicked and having that auto-connect to a widget named tbl_suche.

    You won't be able to start on passing your own parameters until you write your own connect() statement in code which you can alter. Start by getting the normal itemClicked signal/slot (without your own parameters) working with your own explicit connect(). Then come back for help on C++ lambdas, which you will need to pass your parameters. Do not use the old-style SIGNAL/SLOT() macros in your connect()s, read and follow the patterns in https://wiki.qt.io/New_Signal_Slot_Syntax, where it also shows lambdas for slots when you are ready.



  • Wow, this seems complicated.

    Maybe it is easier to retrieve the needed parameters within the standard slot...

    Thank you anyway, JonB!



  • @Thomas-63
    Sooner or later, you will need to change over to not use the auto-connect and do your own connect()s anyway. And use the new style, not the SIGNAL/SLOT() macros. And then you will be able to use lambdas and pass your own parameters. Sooner you do so, better it will be for you :)


Log in to reply