QThread class does emit signal
I get error when I want to emit a signal from inside of my consumer class, here the code:
Code:
#ifndef CONSUMER_H
#define CONSUMER_H
#include <QSemaphore>
#include <QQueue>
extern QQueue<QByteArray> queue;
{
public:
void run();
signals:
};
void Consumer::run()
{
for(;;)
{
if(queue.size() > 0)
{
usedBytes.acquire();
emit sendPackToAllComponents(pack);
freeBytes.release();
qDebug() << "pack=" <<pack;
}
}
}
#endif // CONSUMER_H
And here's how I connected the signal to the slot of another object inside main()
Code:
Consumer *consumer = new Consumer();
rs485 *rs_485 = new rs485();
exhaustSystem *MyExhaust = new exhaustSystem();
packet.append(0x04);
consumer->start();
rs_485->rs485DataAquisition(packet);
This is the exhaust class where it's SLOT is connected to the consumer thread SendTOALLOBJECT SIGNAL:
Code:
class exhaustSystem
: public QObject{
Q_OBJECT
public:
explicit exhaustSystem
(QObject *parent
= 0);
signals:
void stop_diesel();
public slots:
.....
Re: QThread class does emit signal
You forgot to tell us what the error is.
Re: QThread class does emit signal
Hi,
Your Consumer class needs the Q_OBJECT macro: