Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - compiler won't recognize "connect"

Tags:

qt

qt4

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!

like image 641
thnkwthprtls Avatar asked Sep 10 '13 19:09

thnkwthprtls


People also ask

How do I use Qt connect?

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);

What is QObject :: connect?

[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.

Can we connect signal to signal in Qt?

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.


1 Answers

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)

like image 69
Zlatomir Avatar answered Sep 28 '22 05:09

Zlatomir