Solved Signal & Slot weard error (Qt 5.7.1)
-
Hi,
can someone tell my why when I use this:connect(window,&MainWindow::sendHistoryRequestWithMarker,pbxConneciton,&PBXConnect::getHistoryCallUpdates);
I get an compiler error:
C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char ,Qt::ConnectionType) const': cannot convert argument 2 from 'void (__cdecl MainWindow:: )(QString &)' to 'const char *', and this:
connect(window,SIGNAL(sendHistoryRequestWithMarker(QString&)),pbxConneciton,SLOT(getHistoryCallUpdates(QString&)));
emits an error:
QObject::connect: Cannot queue arguments of type 'QString&'
(Make sure 'QString&' is registered using qRegisterMetaType().)one line below I have :
connect(window,&MainWindow::mainwindowSendUpdate_REQ,pbxConneciton,&PBXConnect::sendUpdate_REQ);
that works perfectly?
-
could you show us the signature of
MainWindow::sendHistoryRequestWithMarker
andPBXConnect::getHistoryCallUpdates
? are you overloading any of these functions? -
Yes, I have :
void getHistoryCallUpdates(); ///and void getHistoryCallUpdates(QString &);
-
I've changed the functions name.
now, when I send the signal I get:
QObject::connect: Cannot queue arguments of type 'QString&'
(Make sure 'QString&' is registered using qRegisterMetaType().) -
ok, 2 more things:
- what's the signature of MainWindow::sendHistoryRequestWithMarker
- what version of Qt are you using?
-
@michalos
Hi
Using the new syntax , you must use cast when you have a overloaded signal.
( same name, different paramters)lIke in
connect(mySpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), mySlider, &QSlider::setValue);
-
@mrjj said in Signal & Slot weard error (Qt 5.7.1):
you must use cast when you have a overloaded signal
or for Qt>=5.7 qOverload
Edit:
Are you using Qt::QueuedConnection (i.e. sender and receiver are in 2 different threads)?
Do you really mean to pass a non-const QString reference? -
-
Could you answer all pending questions?
- Are you using Qt::QueuedConnection (i.e. sender and receiver are in 2 different threads)?
- Do you really mean to pass a non-const QString reference?
- what's the signature of MainWindow::sendHistoryRequestWithMarker
- what version of Qt are you using?
-
- Yes, I am using Qt::QueuedConnection
- Can You tell me why passing a non-const QString reference is a problem?
- signature (if I understand correctly) is:
void sendHistoryRequestWithMarkerMain(QString &);
- I am using Qt 5.7.1 (MSVC 2015 64 bit)
Changing the QString & to const QString & did help, but I would appreciate If You could explain me why (or point me in the right direction).
-
@michalos said in Signal & Slot weard error (Qt 5.7.1):
Can You tell me why passing a non-const QString reference is a problem?
Because that string could be modified on the other side so you cannot store "a copy of it" in a queue