Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. connect a signal to lambda function

connect a signal to lambda function

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by
    #1

    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 ?

    JonBJ 1 Reply Last reply
    0
    • ODБOïO ODБOï

      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 ?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        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..";});

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        ODБOïO 1 Reply Last reply
        6
        • VRoninV VRonin

          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..";});

          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          @VRonin thank you very much

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved