Results 1 to 3 of 3

Thread: signals are not working from QThread derived class

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default signals are not working from QThread derived class

    Hi all,

    Application couldn't receive signal from QThread object.

    I have implemented this way:

    workerthread.h:
    ----------------------
    Qt Code:
    1. #ifndef WORKERTHREAD_H
    2. #define WORKERTHREAD_H
    3.  
    4. #include <QThread>
    5.  
    6. class workerthread : public QThread
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit workerthread(QObject *parent = 0);
    11. void run();
    12.  
    13. signals:
    14. void signal_worker_thread();
    15. };
    16.  
    17. #endif // WORKERTHREAD_H
    To copy to clipboard, switch view to plain text mode 

    workerthread.cpp
    -------------------------
    Qt Code:
    1. #include "workerthread.h"
    2. #include <QDebug>
    3.  
    4. workerthread::workerthread(QObject *parent) :
    5. QThread(parent)
    6. {
    7. }
    8.  
    9. void workerthread::run()
    10. {
    11. for(int i = 0; i < 10; ++ i)
    12. {
    13. qDebug() << "workerthread::signal_worker_thread()";
    14. emit signal_worker_thread();
    15. }
    16. return;
    17. }
    To copy to clipboard, switch view to plain text mode 

    WorkerThread is derived from QThread and overridden Run() method.
    I have launched this thread on GUI - button click event to do background process.

    Button click slot event:
    ---------------------------------
    Qt Code:
    1. void ProductNameDialog::slotButtonClicked()//
    2. {
    3. workerthread *pthread = new workerthread();
    4. QObject::connect(pthread, SIGNAL(signal_worker_thread()), this, SLOT(slotTest()));
    5.  
    6. pthread->start();
    7. pthread->wait();
    8.  
    9. accept();
    10. return;
    11. }
    To copy to clipboard, switch view to plain text mode 


    I have tested with sample Qt-GUI MainWindow application. It's working fine.

    When I integrated into my application, slotTest() is not fired. I hope, I am missing something. Can somebody suggest me what I am missing here.

    Thanks in advance.
    Last edited by high_flyer; 16th September 2013 at 10:56. Reason: code tags

Similar Threads

  1. Problems with signals and slots in derived class
    By ittod in forum Qt Programming
    Replies: 6
    Last Post: 21st May 2013, 22:16
  2. Signals not working in a QThread
    By curreli in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2010, 16:04
  3. Moving QObject to QThread causes signals to stop working
    By Ban-chan in forum Qt Programming
    Replies: 8
    Last Post: 13th July 2010, 21:39
  4. QThread and signals (linux/UNIX signals not Qt Signals)
    By Micawber in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2007, 22:18
  5. Signal/slot looking in base class, not derived class
    By georgie in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2006, 07:36

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.