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 SIGNAL from object to Lambda in main(). How?
Forum Updated to NodeBB v4.3 + New Features

Connect SIGNAL from object to Lambda in main(). How?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 3.1k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bogong
    wrote on 7 Nov 2019, 14:12 last edited by bogong 11 Jul 2019, 14:23
    #1

    Hello all!
    What is there right way to call lambda function in Main by connecting it to signal?

    int main(int inCounter, char *inArguments[]) {
    ...
    Object* oObject = new aObject();
    QObject::connect(oObject,SIGNAL(signal()),???,???);
    ...
    }
    

    I've been trying to connect in following manual but it's not working.

    QObject::connect(
    	oObject3,SIGNAL(sCreated()),
    	[](){
    		aLOG << "1111";
    	}
    );
    

    There are this error:

    ../Plain/main.cpp:32:3: error: no matching function for call to 'connect'
                    QObject::connect(
                    ^~~~~~~~~~~~~~~~
    /Users/alexandr/Tools/Qt/5.12.5/clang_64/lib/QtCore.framework/Headers/qobject.h:463:41: note: candidate function not viable: no known conversion from '(lambda at ../Plain/main.cpp:34:4)' to 'const char *' for 3rd argument
    inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
    
    O 1 Reply Last reply 7 Nov 2019, 14:20
    0
    • B bogong
      7 Nov 2019, 14:12

      Hello all!
      What is there right way to call lambda function in Main by connecting it to signal?

      int main(int inCounter, char *inArguments[]) {
      ...
      Object* oObject = new aObject();
      QObject::connect(oObject,SIGNAL(signal()),???,???);
      ...
      }
      

      I've been trying to connect in following manual but it's not working.

      QObject::connect(
      	oObject3,SIGNAL(sCreated()),
      	[](){
      		aLOG << "1111";
      	}
      );
      

      There are this error:

      ../Plain/main.cpp:32:3: error: no matching function for call to 'connect'
                      QObject::connect(
                      ^~~~~~~~~~~~~~~~
      /Users/alexandr/Tools/Qt/5.12.5/clang_64/lib/QtCore.framework/Headers/qobject.h:463:41: note: candidate function not viable: no known conversion from '(lambda at ../Plain/main.cpp:34:4)' to 'const char *' for 3rd argument
      inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal,
      
      O Offline
      O Offline
      ODБOï
      wrote on 7 Nov 2019, 14:20 last edited by
      #2

      @bogong
      with the new signal/slot syntax

         QObject* oObject = new QObject();
      
          QObject::connect(oObject,&QObject::destroyed,[](){
              qDebug()<< "object destructed";
          });
      
          oObject->deleteLater();
      
      1 Reply Last reply
      2
      • B Offline
        B Offline
        bogong
        wrote on 7 Nov 2019, 14:38 last edited by
        #3

        Issue closed.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Perdrix
          wrote on 2 May 2025, 17:33 last edited by Perdrix 5 Feb 2025, 17:36
          #4
          This post is deleted!
          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