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
Forum Update on Monday, May 27th 2025

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.
  • O Offline
    O Offline
    ODБOï
    wrote on 24 Aug 2018, 13:30 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 ?

    J 1 Reply Last reply 24 Aug 2018, 13:41
    0
    • O ODБOï
      24 Aug 2018, 13:30

      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 ?

      J Online
      J Online
      JonB
      wrote on 24 Aug 2018, 13:41 last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      1
      • V Offline
        V Offline
        VRonin
        wrote on 24 Aug 2018, 13:43 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

        O 1 Reply Last reply 24 Aug 2018, 13:50
        6
        • V VRonin
          24 Aug 2018, 13:43

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

          O Offline
          O Offline
          ODБOï
          wrote on 24 Aug 2018, 13:50 last edited by
          #4

          @VRonin thank you very much

          1 Reply Last reply
          0

          1/4

          24 Aug 2018, 13:30

          • Login

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