I'm working in Qt 4.7, and I have a portion of code with signals and slots. It's set up just as normal, namely:
#include <QObject>
//Earlier code...
connect(my_thread, SIGNAL(started()), other_thread, SLOT(process()));
connect(my_thread, SIGNAL(finished()), third_thread, SLOT(some_slot()));
//Later code...
However, when I build it gives an error for each statement saying "C3861: 'connect': identifier not found" Does anyone have any ideas why this may be? Thanks!
To connect the signal to the slot, we use QObject::connect(). There are several ways to connect signal and slots. The first is to use function pointers: connect(sender, &QObject::destroyed, this, &MyObject::objectDestroyed);
[static] QMetaObject::Connection QObject::connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type = Qt::AutoConnection) Creates a connection of the given type from the signal in the sender object to the method in the receiver object.
This ensures that truly independent components can be created with Qt. You can connect as many signals as you want to a single slot, and a signal can be connected to as many slots as you need. It is even possible to connect a signal directly to another signal.
If you use connect in code that is not part of a QObject
derived class, precede the connect with the QObject::
, so the code will become:
//Earlier code...
QObject::connect(my_thread, SIGNAL(started()), other_thread, SLOT(process()));
LE: basically you call the static connect method and when you are not in the scope of a QObject (or a QObject derived class) you need to fully specify the connect you want to call, else the compiler doesn't find it (or it might find a wrong connect in the current scope)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With