2

I am trying to use this statement . I am using QT 5.1 in VS2012

connect(ui.pushButton_next, SIGNAL(clicked()), []{
    std::cout << "clicked" << std::endl;
});

I get

error C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const' : cannot convert parameter 3 from 'newAccount::{ctor}::' to 'const char *' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Any suggestion on what I might be doing wrong ?

6
  • 1
    Isn't ui a pointer? And NO, you cannot use the old syntax with a lambda, you have to use the new connect syntax. Commented Jan 24, 2014 at 20:50
  • ui is an object that has the pointer pushbutton_next Commented Jan 24, 2014 at 21:03
  • You aren't using a designer form then, because the ui that Qt generates in such cases is a pointer. Commented Jan 24, 2014 at 21:09
  • I am using VStudio plugin Commented Jan 24, 2014 at 21:12
  • 1
    Take a look at this page here, it explains the new connection syntax in Qt5 qt-project.org/wiki/New_Signal_Slot_Syntax Commented Jan 24, 2014 at 21:25

1 Answer 1

4

Looking at the documentation, the overloads of the connect method that support the SIGNAL and SLOT macros do not appear to take in a Functor object - this is only supported by this overload that takes in a PointerToMemberFunction.

The right syntax for your code is:

connect(ui.pushButton_next, &QObject::clicked, []{
    std::cout << "clicked" << std::endl;
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.