I get error when I want to emit a signal from inside of my consumer class, here the 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
#ifndef CONSUMER_H
#define CONSUMER_H
#include <QSemaphore>
#include <QQueue>
extern QSemaphore freeBytes;
extern QSemaphore usedBytes;
extern QQueue<QByteArray> queue;
class Consumer : public QThread
{
public:
void run();
signals:
void sendPackToAllComponents(QByteArray );
};
void Consumer::run()
{
for(;;)
{
if(queue.size() > 0)
{
usedBytes.acquire();
QByteArray pack = queue.dequeue();
emit sendPackToAllComponents(pack);
freeBytes.release();
qDebug() << "pack=" <<pack;
}
}
}
#endif // CONSUMER_H
To copy to clipboard, switch view to plain text mode
And here's how I connected the signal to the slot of another object inside main()
Consumer *consumer = new Consumer();
rs485 *rs_485 = new rs485();
exhaustSystem *MyExhaust = new exhaustSystem();
packet.append(0x04);
consumer->start();
rs_485->rs485DataAquisition(packet);
QCoreApplication a(argc, argv);
Consumer *consumer = new Consumer();
rs485 *rs_485 = new rs485();
exhaustSystem *MyExhaust = new exhaustSystem();
QByteArray packet;
packet.append(0x04);
consumer->start();
QObject::connect(MyExhaust, SIGNAL(EXHAUST_SendToRS485(QByteArray)), rs_485, SLOT(rs485DataAquisition(QByteArray)));
QObject::connect(consumer, SIGNAL(sendPackToAllComponents(QByteArray)),MyExhaust, SLOT(EXHAUST_DataReceive(QByteArray)));
rs_485->rs485DataAquisition(packet);
To copy to clipboard, switch view to plain text mode
This is the exhaust class where it's SLOT is connected to the consumer thread SendTOALLOBJECT SIGNAL:
class exhaustSystem
: public QObject{
Q_OBJECT
public:
explicit exhaustSystem
(QObject *parent
= 0);
signals:
void stop_diesel();
public slots:
.....
class exhaustSystem : public QObject
{
Q_OBJECT
public:
explicit exhaustSystem(QObject *parent = 0);
signals:
void EXHAUST_SendToRS485(QByteArray );
void stop_diesel();
public slots:
void EXHAUST_DataReceive(QByteArray);
.....
To copy to clipboard, switch view to plain text mode
Bookmarks