Results 1 to 3 of 3

Thread: QThread class does emit signal

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QThread class does emit signal

    I get error when I want to emit a signal from inside of my consumer class, here the code:

    Qt Code:
    1. #ifndef CONSUMER_H
    2. #define CONSUMER_H
    3.  
    4. #include <QSemaphore>
    5. #include <QQueue>
    6.  
    7. extern QSemaphore freeBytes;
    8. extern QSemaphore usedBytes;
    9. extern QQueue<QByteArray> queue;
    10.  
    11. class Consumer : public QThread
    12. {
    13. public:
    14. void run();
    15. signals:
    16. void sendPackToAllComponents(QByteArray );
    17. };
    18.  
    19. void Consumer::run()
    20. {
    21. for(;;)
    22. {
    23. if(queue.size() > 0)
    24. {
    25. usedBytes.acquire();
    26. QByteArray pack = queue.dequeue();
    27. emit sendPackToAllComponents(pack);
    28. freeBytes.release();
    29.  
    30. qDebug() << "pack=" <<pack;
    31.  
    32. }
    33. }
    34. }
    35. #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()

    Qt Code:
    1. QCoreApplication a(argc, argv);
    2. Consumer *consumer = new Consumer();
    3. rs485 *rs_485 = new rs485();
    4. exhaustSystem *MyExhaust = new exhaustSystem();
    5. QByteArray packet;
    6. packet.append(0x04);
    7. consumer->start();
    8. QObject::connect(MyExhaust, SIGNAL(EXHAUST_SendToRS485(QByteArray)), rs_485, SLOT(rs485DataAquisition(QByteArray)));
    9. QObject::connect(consumer, SIGNAL(sendPackToAllComponents(QByteArray)),MyExhaust, SLOT(EXHAUST_DataReceive(QByteArray)));
    10.  
    11. 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:
    Qt Code:
    1. class exhaustSystem : public QObject
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit exhaustSystem(QObject *parent = 0);
    6.  
    7. signals:
    8. void EXHAUST_SendToRS485(QByteArray );
    9. void stop_diesel();
    10. public slots:
    11.  
    12. void EXHAUST_DataReceive(QByteArray);
    13. .....
    To copy to clipboard, switch view to plain text mode 
    Last edited by saman_artorious; 14th June 2012 at 14:06. Reason: updated contents

Similar Threads

  1. Emit signal outside run() in QThread
    By naturalpsychic in forum Qt Programming
    Replies: 4
    Last Post: 26th March 2012, 16:31
  2. emit signal and recognizing in a different class
    By salmanmanekia in forum Newbie
    Replies: 11
    Last Post: 18th October 2011, 08:19
  3. Replies: 2
    Last Post: 3rd May 2011, 20:22
  4. Replies: 3
    Last Post: 7th April 2011, 11:09
  5. QThread don' stop (or the signal don't emit)
    By msdark in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2011, 23:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.