Solved Trouble with connect()...
-
I wish to connect/sync the vertical scroll bars of 2 plain text edits together like so in C++:
connect(this->textEdit_T->verticalScrollBar, SIGNAL(valueChanged(int)), this->textEdit_S->verticalScrollBar, SLOT(setValue(int))); connect(this->textEdit_S->verticalScrollBar, SIGNAL(valueChanged(int)), this->textEdit_T->verticalScrollBar, SLOT(setValue(int)));
However, I get this error:
error C3867: 'QAbstractScrollArea::verticalScrollBar': non-standard syntax; use '&' to create a pointer to member
And when I add "&"' to the senders I get this error:
error C2276: '&': illegal operation on bound member function expression
My apologies, this is probobaly a very simple mix up but I am a little confused.
-
@alexanderalexander said in Trouble with connect()...:
this->textEdit_T->verticalScrollBar
This is a function so it has to end with
()
, thus:this->textEdit_T->verticalScrollBar()
-
Also, I strongly recommend using new signal-slot connection syntax, it will avoid you many troubles! https://doc.qt.io/qt-5/signalsandslots-syntaxes.html
-
@sierdzio
My apologies, I meant to include this in my example above:connect(this->textEdit_T->verticalScrollBar(), SIGNAL(valueChanged(int)), this->textEdit_S->verticalScrollBar(), SLOT(setValue(int))); connect(this->textEdit_S->verticalScrollBar(), SIGNAL(valueChanged(int)), this->textEdit_T->verticalScrollBar(), SLOT(setValue(int)));
This ^ causes another error, telling me that there is no overloaded function (of the class I call this in)
that matches the argument list. When I try to compile it then tells me this:Error C2664 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char *,Qt::ConnectionType) const': cannot convert argument 1 from 'QScrollBar *' to 'const QObject *' KOALA C:\WorkSpace\KOALA\EPRateMod.cxx 85
Note: I am including QObject
-
@alexanderalexander said in Trouble with connect()...:
cannot convert argument 1 from 'QScrollBar *' to 'const QObject *'
You forgot to include QScrollBar header file. And please don't use old signals/slot syntax.
-
@alexanderalexander The error message is talking about connect() with different parameters than what you have in these two lines - are you sure the error message comes from one of these lines?
You really should try new connect syntax as @sierdzio suggested. -
Thanks for all the help guys, figured it was just a stupid mistake like that. Just wanted to get this working and then I'll take everyone's advice and use the newer signal/slot syntax.