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

connect a signal to lambda function



  • Hi,
    I'm trying to connect a signal to a lambda function like this:

    //main.cpp
    FileLoader fl;
       QObject::connect(
            fl, &FileLoader::objChanged,
            [=]( const QString &newValue ) { qDebug()<< "lambda called..";}
        );
    
    

    the signal is defined like this :

    void  objChanged(QString)
    

    this is the output :

    C:\udp_inspector\main.cpp:25: erreur : no matching function for call to 'QObject::connect(FileLoader&, void (FileLoader::*)(QString), qMain(int, char**)::<lambda(QString)>)'
         QObject::connect(fl,FileLoader::objChanged,[=](QString newObj){qDebug()<<newObj;});
                                                                                          ^
    

    Can someone tell me how to do this please ?



  • This post is deleted!


  • The first argument must be a pointer to QObject.
    Change QObject::connect(fl, &FileLoader::objChanged, [=]( const QString &newValue ) { qDebug()<< "lambda called..";}); to QObject::connect(&fl, &FileLoader::objChanged, [=]( const QString &newValue ) { qDebug()<< "lambda called..";});



  • @VRonin thank you very much


Log in to reply