Results 1 to 4 of 4

Thread: why doesn't signal gets emiited?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Location
    Australia
    Posts
    44
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default why doesn't signal gets emiited?

    i dont understand why are my signals not working in this multi threaded app

    file.h:
    Qt Code:
    1. #include <QObject>
    2.  
    3.  
    4. class FThread;
    5.  
    6. class File : public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. File(QObject *parent = 0);
    11. FThread *fthread;
    12. public slots:
    13. void print();
    14.  
    15.  
    16.  
    17. };
    To copy to clipboard, switch view to plain text mode 

    fthread.h

    Qt Code:
    1. #include <QThread>
    2.  
    3.  
    4. class File;
    5. class FThread : public QThread
    6. {
    7. Q_OBJECT
    8. public:
    9.  
    10.  
    11. FThread(QObject *parent = 0);
    12. virtual void run();
    13. File *f;
    14. void sampleFunc();
    15. signals:
    16. void done();
    17.  
    18.  
    19. };
    To copy to clipboard, switch view to plain text mode 
    file.cpp:

    Qt Code:
    1. #include "file.h"
    2. #include <QDebug>
    3. #include "fthread.h"
    4.  
    5. File::File(QObject *parent) :
    6. QObject(parent)
    7. {
    8.  
    9. connect(fthread,SIGNAL(done()),this,SLOT(print()));
    10.  
    11. }
    12. void File::print(){
    13. qDebug()<<"printing from File object";
    14. fthread.exit();
    15. }
    To copy to clipboard, switch view to plain text mode 
    fthread.cpp

    Qt Code:
    1. #include "fthread.h"
    2. #include "file.h"
    3. #include <QDebug>
    4.  
    5. FThread::FThread(QObject *parent) :
    6. QThread(parent)
    7. {
    8.  
    9. f=new File();
    10.  
    11.  
    12. }
    13.  
    14. void FThread::run(){
    15.  
    16. sampleFunc();
    17. this->exec();
    18.  
    19. }
    20.  
    21. void FThread::sampleFunc()
    22. {
    23. emit done(); //<<--------------SIGNAL SHOULD BE EMITTED FROM HERE
    24. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp:
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include <QDebug>
    3. #include "fthread.h"
    4. int main(int argc, char *argv[])
    5. {
    6. QCoreApplication a(argc, argv);
    7.  
    8. qDebug()<<"App started";
    9. FThread fthread;
    10. fthread.start();
    11. fthread.wait();
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    NOTE:

    i get following output:

    App started
    The program has unexpectedly finished.
    ...path/Thread exited with code 0

    means it is exiting without error


    any help please!!!!!!!
    Last edited by naturalpsychic; 26th January 2011 at 14:36.
    Life is like a dream, sometimes it is good and somtimes it is bad, but in the end it is over

Similar Threads

  1. Connect signal/signal in Qt Designer
    By jlemaitre in forum Newbie
    Replies: 1
    Last Post: 22nd September 2010, 15:53
  2. signal mapping on pushbutton signal clicked
    By wagmare in forum Qt Programming
    Replies: 2
    Last Post: 17th March 2009, 07:54
  3. Signal-Signal Connections Between Threads
    By PhilippB in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2008, 18:27
  4. signal of QListWidget doesn't work
    By vito49 in forum Qt Programming
    Replies: 10
    Last Post: 1st October 2008, 05:07
  5. QUrlOperator doesn't emit finished signal
    By hayati in forum Qt Programming
    Replies: 16
    Last Post: 26th March 2007, 20:25

Tags for this Thread

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.