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

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



  • 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,
    


  • @bogong
    with the new signal/slot syntax

       QObject* oObject = new QObject();
    
        QObject::connect(oObject,&QObject::destroyed,[](){
            qDebug()<< "object destructed";
        });
    
        oObject->deleteLater();
    


  • Issue closed.


Log in to reply