2
votes

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 ?

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. - dtech
ui is an object that has the pointer pushbutton_next - MistyD
You aren't using a designer form then, because the ui that Qt generates in such cases is a pointer. - dtech
I am using VStudio plugin - MistyD
Take a look at this page here, it explains the new connection syntax in Qt5 qt-project.org/wiki/New_Signal_Slot_Syntax - dtech

1 Answers

4
votes

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