Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

New signals & slots connection syntax with Qt5

$
0
0
Hi, I have a QLineEdit and a QPushButton. I’d like the button to gain focus when the return key is pressed while typing anything in the QLineEdit. Therefore I wrote : QObject::connect(_ui->findExpressionLineEdit, &QLineEdit::returnPressed, _ui->findPushButton, &QWidget::setFocus); But such code doen’t want to compile : /home/kevina/Documents/editor/src/findWidget.cpp:56:14: error: no matching member function for call to ‘connect’ QObject::connect(_ui->findExpressionLineEdit, &QLineEdit::returnPressed, _ui->findPushButton, &QWidget::setFocus); ~~~~~~~~~^~~~~~~ /usr/include/qt/QtCore/qobject.h:198:36: note: candidate function not viable: no known conversion from ‘void (QLineEdit::*)()’ to ‘const char *’ for 2nd argument static QMetaObject::Connection connect(const QObject *sender, const char *signal, ^ /usr/include/qt/QtCore/qobject.h:201:36: note: candidate function not viable: no known conversion from ‘void (QLineEdit::*)()’ to ‘const QMetaMethod’ for 2nd argument static QMetaObject::Connection connect(const QObject *sender, const QMetaMethod &signal, ^ /usr/include/qt/QtCore/qobject.h:440:41: note: candidate function not viable: no known conversion from ‘void (QLineEdit::*)()’ to ‘const char *’ for 2nd argument inline QMetaObject::Connection QObject::connect(const QObject *asender, const char *asignal, ^ /usr/include/qt/QtCore/qobject.h:214:43: note: candidate template ignored: couldn’t infer template argument ‘Func2’ static inline QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, ^ /usr/include/qt/QtCore/qobject.h:244:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot) ^ /usr/include/qt/QtCore/qobject.h:267:13: note: candidate function template not viable: requires 3 arguments, but 4 were provided connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, Func2 slot) ^ 1 error generated. But this code does work : QObject::connect(_ui->findExpressionLineEdit, &QLineEdit::returnPressed, [this] () {           _ui->findPushButton->setFocus();     }); But I’d like to use the first syntax wich is more logical and concise. Any clue about that ? Thx ;)

Viewing all articles
Browse latest Browse all 13965