SLOT 'setEnable(true)' nicht gefunden



  • Hallo,

    ich möchte bei Klick auf Btn1 den Btn2 anzeigen.

    QObject::connect(btn1, SIGNAL(clicked()), btn2, SLOT(setEnabled(true)));
    

    aber ich bekomme hier die Fehlermeldung:
    QObject::connect(btn1, SIGNAL(clicked()), btn2, SLOT(setEnabled(true)));

    Wieso?



  • @getit
    Wenn Sie mein Schuele-Deutsch verstehen koennen ;)

    You cannot pass a parameter to the function in your SLOT declaration. You could only write SLOT(setEnabled(bool)). To pass your value of true, you either need to write it as a lambda or write a dedicated function to call the btn2.setEnabled(true).



  • @getit Sorry I don't speak German.
    You can try using a lambda.

    QObject::connect(btn1, QPushButton::clicked, [this](){
        btn2->setEnabled(true)
    }
    
    • You cannot use parameter in signal-slot connection
    • QPushButton::clicked() and `QWidget::setEnabled(bool) are not compatible


  • @Gojir4 said in SLOT 'setEnable(true)' nicht gefunden:

    @getit Sorry I don't speak German.
    You can try using a lambda.

    QObject::connect(btn1, QPushButton::clicked, [this](){
        btn2->setEnabled(true)
    }
    
    • You cannot use parameter in signal-slot connection
    • QPushButton::clicked() and `QWidget::setEnabled(bool) are not compatible

    Vielen Dank!!

    QObject::connect(btn1, &QPushButton::clicked, [btn2]() {
            btn2->setEnabled(true);
        });
    

Log in to reply
 

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