My program was working fine but I wanted to add an extra signal into it to display an updated value. This is the first time the signal was actually coming from the class itself, so I decided to use this
as you shall see.
The Program
In my header file, as usual I declare my signal:
signals:
void NotifyStatusUpdated(const QString& value);
private:
SetupTab& m_setupTab;
Instrument& m_instrument;
In the .cpp, the final thing constructed is the signal:
WireMessages();
emit NotifyStatusUpdated(tr("Long wait time (Ms) updated : %1 ").arg(long_wait));
Then below I have this:
void SetupViewManager::WireMessages()
{
connect(&m_instrument, &Instrument::NotifyErrorDetected,
&m_setupTab, &SetupTab::onStatusUpdated); //this works
connect(&m_instrument, &Instrument::NotifyStatusUpdated,
&m_setupTab, &SetupTab::onStatusUpdated); //this works
connect(this, &Instrument::NotifyStatusUpdated, //this does not work (it doesn't build)!
&m_setupTab, &SetupTab::onStatusUpdated);
}
So in my class reference m_instrument
, I have another signal which has the same name. So here I want to call the signal from this
class instead.
The Error
error: no matching member function for call to 'connect'
connect(this, &Instrument::NotifyStatusUpdated,
^~~~~~~
This just does not seem right to me? What stupid mistake am I making?
Автор | Тема: ошибка: no matching member function for call to ‘connect’ (Прочитано 3787 раз) |
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
|
||||||
This topic has been deleted. Only users with topic management privileges can see it.
Hello,
I am trying to use QSignalMapper to map many similar identifiable QLineEdit widgets in my program.
I am following instructions on this page: https://doc.qt.io/qt-5/qsignalmapper.html#details
However I get a compilation error (the title). I don’t understand, QWidget inherits from QObject, so the member function exists, but I must be doing something wrong with the parameters. Help
The line that produces this error is: (in the .cpp file)
connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
Here is the source code and header of the class I’m implementing:
lineedityarnsetpoint.h
#ifndef LINEEDITYARNSETPOINT_H
#define LINEEDITYARNSETPOINT_H
#include <QWidget>
#include <QSignalMapper>
#include <QLineEdit>
#include <QGridLayout>
//#include <QObject>
class LineEditYarnSetpoint : public QWidget
{
Q_OBJECT
public:
LineEditYarnSetpoint(const int n, QWidget *parent = nullptr);
signals:
void editingFinished(const int feeder_index);
private:
QSignalMapper *signalMapper;
};
#endif // LINEEDITYARNSETPOINT_H
lineedityarnsetpoint.cpp
#include "lineedityarnsetpoint.h"
LineEditYarnSetpoint::LineEditYarnSetpoint(const int n, QWidget *parent)
: QWidget(parent)
{
signalMapper = new QSignalMapper(this);
QGridLayout *gridLayout = new QGridLayout;
for (int i = 0; i < n; ++i)
{
QLineEdit *lineEdit = new QLineEdit();
/*ERROR*/connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
signalMapper->setMapping(lineEdit, i);
gridLayout->addWidget(lineEdit, 0, i);
}
connect(signalMapper, &QSignalMapper::mappedInt, this, &LineEditYarnSetpoint::editingFinished);
setLayout(gridLayout);
}
Thanks in advance!
@t-vanbesien said in no matching member function for call to ‘connect’:
/*ERROR*/connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
void QSignalMapper::map(QObject *sender) expects a QObject *sender
parameter. void QLineEdit::editingFinished() does not provide one.
OIC, void QSignalMapper::map() does not take any parameter. But now there are two slots of the same name which differ only by parameter. Then you may need to use qOverload<>()
/QOverload<>::of()
to specify which one? Maybe QOverload<>::of<>(&QSignalMapper::map)
or QOverload<>::of<void>(&QSignalMapper::map)
? (I don’t know how you specify «the one with no parameter»).
Ah, see https://stackoverflow.com/questions/68552698/connecting-qsignalmapper-qt-5-15-2 ?
Also, if you had copied and pasted the full error details from the compiler I think it would have said a bit more than just no matching member function for call to 'connect'
, does it not show information about the various possible slot method overloads?
@JonB
Here is the full error message:
/Users/thomasvanbesien/IHM_Bobink/lineedityarnsetpoint.cpp:14: error: no matching member function for call to 'connect'
../IHM_Bobink/lineedityarnsetpoint.cpp:14:3: error: no matching member function for call to 'connect'
connect(lineEdit, &QLineEdit::editingFinished, signalMapper, &QSignalMapper::map);
^~~~~~~
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:181: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,
^
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:184: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,
^
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:432: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,
^
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:201: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,
^
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:242:13: note: candidate template ignored: couldn't infer template argument 'Func2'
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
^
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:287:13: note: candidate template ignored: couldn't infer template argument 'Func2'
connect(const typename QtPrivate::FunctionPointer<Func1>::Object *sender, Func1 signal, const QObject *context, Func2 slot,
^
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:233: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)
^
/Users/thomasvanbesien/Qt/6.4.2/macos/lib/QtCore.framework/Headers/qobject.h:276: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)
^
@t-vanbesien said in no matching member function for call to ‘connect’:
couldn’t infer template argument ‘Func2’
I’m not sure, but this is probably the one that relates to your situation.
In any case you need to do the «qoverload» I suggested and is in the SO post.
@JonB
Thank you for the help. I was able to make it work, I changed the erroneous line to:
connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of<>(&QSignalMapper::map));
I’m not completely sure why it works. C++ templates are still a bit fuzzy to me, but I’ll post an explanation when I understand exactly what the problem was.
@t-vanbesien said in no matching member function for call to ‘connect’:
connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of<>(&QSignalMapper::map));
I don’t believe that is a working copy/paste, I think you mean QOverload<>::of(&QSignalMapper::map)
?
C++ templates are still a bit fuzzy to me, but I’ll post an explanation when I understand exactly what the problem was.
There are 2 possible overloads: QSignalMapper::map()
& QSignalMapper::map(QObject *)
.
QOverload<>::of(...)
picks the first one (no parameters), QOverload<QObject *>::of(...)
picks the second one. The bit inside <...>
specifies the parameters. It’s kind of like a cast.
@JonB said in no matching member function for call to ‘connect’:
I don’t believe that is a working copy/paste, I think you mean
QOverload<>::of(&QSignalMapper::map)
?
No, the line I copy/pasted does compile and run and has the expected behavior.
@t-vanbesien
Interesting. Could you tell me/give me a reference to where you got an example or documentation which uses QOverload<...>::of<...>(...)
rather than QOverload<...>::of(...)
, please? Note the bit I am asking about is the ::of<>
having a <...>
segment?
@JonB
I don’t know ? I’m not sure I understand the question. I used
QOverload<...>::of<...>()
because you wrote it in your first answer to this post. I can’t find any documentation about it. If you want a working example I can share the class .cpp and .h of the class and the small debug function I made to make sure it is working properly. You can put it in an empty qt project to check.
@t-vanbesien said in no matching member function for call to ‘connect’:
because you wrote it in your first answer to this post.
Damn! So I did, I was guessing at that point! Now I know better, from the SO link I gave you
I suggest that you try copy/paste the following line to replace yours:
connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of(&QSignalMapper::map));
Even though your ::of<>(
apparently works, it should be ::of(
. Don’t confuse yourself by using my guessed-syntax, for when you come back to it.
@JonB
I replaced the line so that now it is:
connect(lineEdit, &QLineEdit::editingFinished, signalMapper, QOverload<>::of(&QSignalMapper::map));
And everything is still working properly.
By the way, you wrote ‘IOC’ in one of your answers, what does it mean ?
@t-vanbesien said in no matching member function for call to ‘connect’:
By the way, you wrote ‘IOC’ in one of your answers, what does it mean ?
I wrote OIC
=> O-I-C
=> «Oh I See»
QScrollArea, QScrollBar
Добрый день.
Я воспользовался прримером
Image Viewer
.
У меня есть
QScrollArea *scrollArea;У QScrollArea есть вертикальные и горизонатальные QScrollBar.
Я хочу к сигналам изменения scrollArea привязать пустой слот:connect(scrollArea, &QScrollBar::rangeChanged, this, &ImageViewer::updateSize);Но получаю ошибку: no matching member function for call to ‘connect’
Скажите пожалуйста, как привязать слот к сигналу изменения QScrollArea?
Вам это нравится? Поделитесь в социальных сетях!
No_name0 0 / 0 / 0 Регистрация: 13.07.2020 Сообщений: 21 |
||||
1 |
||||
Проблемы с коннектом11.10.2020, 22:10. Показов 599. Ответов 13 Метки нет (Все метки)
кусочек кода (все либы подключены)
в заголовочном файле в паблик-члене написан слот.
0 |
_SayHello 874 / 535 / 175 Регистрация: 30.07.2015 Сообщений: 1,739 |
||||||||
11.10.2020, 22:18 |
2 |
|||||||
No_name0, прототип в хидере случайно не так опредлен? Если да, то в CPP тоже void надо
Ну и слот должен быть определен после
1 |
0 / 0 / 0 Регистрация: 13.07.2020 Сообщений: 21 |
|
11.10.2020, 22:32 [ТС] |
3 |
слот определён после public slots, а там где надо передать void в качестве аргумента, то не выходит ничего (((((
0 |
_SayHello 874 / 535 / 175 Регистрация: 30.07.2015 Сообщений: 1,739 |
||||
11.10.2020, 22:35 |
4 |
|||
No_name0, сигнал и слот должны иметь одинаковую сигнатуру. Сигнал такой:
Значит и слот должен иметь булёвый параметр
1 |
0 / 0 / 0 Регистрация: 13.07.2020 Сообщений: 21 |
|
11.10.2020, 22:37 [ТС] |
5 |
А не подскажете как преобразовать слот или сигнал в булевый тип? что-то совсем голова не работает
0 |
_SayHello 874 / 535 / 175 Регистрация: 30.07.2015 Сообщений: 1,739 |
||||
11.10.2020, 22:39 |
6 |
|||
No_name0,
1 |
0 / 0 / 0 Регистрация: 13.07.2020 Сообщений: 21 |
|
11.10.2020, 22:45 [ТС] |
7 |
почему-то всё равно не коннектится, от слова совсем
0 |
iSmokeJC Am I evil? Yes, I am! 16956 / 9178 / 2634 Регистрация: 21.10.2017 Сообщений: 20,897 |
||||
12.10.2020, 07:58 |
8 |
|||
No_name0, твой код работает, даже без правок (в части, касающейся коннекта).
1 |
фрилансер 4816 / 4419 / 941 Регистрация: 11.10.2019 Сообщений: 11,653 |
|
12.10.2020, 08:02 |
9 |
что коннект ругается «no matching member function for call to «connect» ругается где?
1 |
0 / 0 / 0 Регистрация: 13.07.2020 Сообщений: 21 |
|
12.10.2020, 08:30 [ТС] |
10 |
Qt creator.
0 |
1392 / 639 / 295 Регистрация: 02.05.2020 Сообщений: 1,490 |
|
12.10.2020, 12:50 |
11 |
void generates(void) попробуйте static void generates() Добавлено через 2 минуты
1 |
No_name0 0 / 0 / 0 Регистрация: 13.07.2020 Сообщений: 21 |
||||
12.10.2020, 16:28 [ТС] |
12 |
|||
0 |
2439 / 1178 / 436 Регистрация: 08.11.2016 Сообщений: 3,262 |
|
12.10.2020, 17:18 |
13 |
No_name0, добавьте в класс Skilet макрос Q_OBJECT
1 |
0 / 0 / 0 Регистрация: 13.07.2020 Сообщений: 21 |
|
12.10.2020, 18:25 [ТС] |
14 |
Спасибо всем! Каким-то чудом заработало, поменяла отладчики, все пошло как по маслу!
0 |
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
12.10.2020, 18:25 |
14 |