c++ - C2665: 'QObject::connect' : none of the 3 overloads could convert all the arguments types -


i have following code in main

         qprocess process;         qobject::connect(&process, &qprocess::error, [](qprocess::processerror error)         {             qdebug() << error;         }, qt::queuedconnection);         bool launched = process.startdetached("d:\temp.exe"); 

and generating error while compiling

    d:\main.cpp:5: error: c2665: 'qobject::connect' : none of 3 overloads convert argument types c:\qt\5.3\msvc2013_64\include\qtcore\qobject.h(205):  'qmetaobject::connection qobject::connect(const qobject *,const char     *,const char *,qt::connectiontype) const' c:\qt\5.3\msvc2013_64\include\qtcore\qobject.h(201): or        'qmetaobject::connection qobject::connect(const qobject *,const qmetamethod &,const qobject *,const qmetamethod &,qt::connectiontype)' c:\qt\5.3\msvc2013_64\include\qtcore\qobject.h(198): or        'qmetaobject::connection qobject::connect(const qobject *,const char     *,const qobject *,const char *,qt::connectiontype)' while trying match argument list '(qprocess *, overloaded-function, runguimode::<lambda_5d6e7ee926a623cea2a0e4469253d55f>, qt::connectiontype)' 

can please me out , tell me doing wrong.

i want connect signal qprocess class lambda

i shouldn't post answer, honest not same question, more complex.

first of all, why first version doesn't work. because can't use additional argument (connection type) without providing receiver. means next wrong.

connect(&process, static_cast<void (qprocess::*)(qprocess::processerror)>         (&qprocess::error),[=](qprocess::processerror perror) {         qwarning() << "error " << perror; },qt::queuedconnection); 

but next correct:

connect(&process, static_cast<void (qprocess::*)(qprocess::processerror)>         (&qprocess::error), , [=](qprocess::processerror perror) {         qwarning() << "error " << perror; },qt::queuedconnection); 

if wonder why, @ qobject.h. make changes in file, more accurate (don't change file!).

//first //connect functor template <typename func1, typename func2> static inline typename qtprivate::qenableif<qtprivate::functionpointer<func2>::argumentcount == -1, qmetaobject::connection>::type connect(const typename qtprivate::functionpointer<func1>::object *sender, func1 signal, func2 slot) {     qdebug("there no here argument connection, isn't it?");     return connect(sender, signal, sender, slot, qt::directconnection); }  //second //connect functor, "context" object defining in event loop going executed template <typename func1, typename func2> static inline typename qtprivate::qenableif<qtprivate::functionpointer<func2>::argumentcount == -1, qmetaobject::connection>::type connect(const typename qtprivate::functionpointer<func1>::object *sender, func1 signal, const qobject *context, func2 slot,         qt::connectiontype type = qt::autoconnection) {     qdebug("this called, , can see need specify context if want use connection type.");     //... 

secondly when run code, get:

qobject::connect: cannot queue arguments of type 'qprocess::processerror' (make sure 'qprocess::processerror' registered using qregistermetatype().)

so need add qregistermetatype<qprocess::processerror>("qprocess::processerror"); before connection.

so final version is:

qregistermetatype<qprocess::processerror>("qprocess::processerror"); qprocess process; connect(&process, static_cast<void (qprocess::*)(qprocess::processerror)>         (&qprocess::error), , [=](qprocess::processerror perror) {     qwarning() << "error " << perror; },qt::queuedconnection); process.start("myprogram"); bool launched = process.startdetached("example"); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -