I am a newbie with Qt. Most of the times Qt developers need to use signals and slots for object communication. I have seen two ways of connecting signals and slots so far.
1)QObject::connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int)));
2)connect(scrollBar, SIGNAL(valueChanged(int)),label, SLOT(setNum(int)));
What is the exact difference between both of them? Why do we have to prefix QObject in the first method?
You call the static version in both aforementioned cases, the signature of which is as follows:
When you are not connecting inside a QObject subclass, you will need to use the scoped variant, respectively, because you will not have an object in place to call it on. Here you can see some code representing the difference.
Not scoped
Scoped
Please note that if you are trying to do this connection within the receiver object, you could even skip the third argument for convenience (i.e. less typing) because the non-static const version will take care of this automatically as per documentation:
QMetaObject::Connection QObject::connect(const QObject * sender, const char * signal, const char * method, Qt::ConnectionType type = Qt::AutoConnection) const