Hello Guy,
I trying to put a while(1) C function in my Qt project.
I want to run it in the background of a specific Gui.
I have been trying to use threads to do it .I tried declaring the thread in main() and my Gui cpp file(infuison.cpp) But there seem to be a problem.
this is what i have done.
QThread: Destroyed while thread is still running
ASSERT failure in QThread::setTerminationEnabled(): "Current thread was not started with QThread.", file thread\qthread_win.cpp, line 574
Invalid parameter passed to C runtime function.
Invalid parameter passed to C runtime function.

Qt Code:
  1. //threading.h
  2. #ifndef THREADINGS_H
  3. #define THREADINGS_H
  4.  
  5. #include <QObject>
  6. #include <QThread>
  7.  
  8. class Threadings : public QObject
  9. {
  10. Q_OBJECT
  11. public:
  12. explicit Threadings(QObject *parent = 0);
  13. void DoSetup(QThread &cThread);
  14. signals:
  15.  
  16. public slots:
  17. void runAlgoMain();
  18.  
  19. };
  20.  
  21. #endif // THREADINGS_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //threadings.cpp
  2.  
  3. #include "threadings.h"
  4.  
  5. extern "C++"
  6. {
  7. #include "test.h"
  8. }
  9.  
  10. Threadings::Threadings(QObject *parent) :
  11. QObject(parent)
  12. {
  13. }
  14.  
  15. void Threadings::DoSetup(QThread &cThread)
  16. {
  17. connect(&cThread,SIGNAL(started()),this,SLOT(runAlgoMain()));
  18. }
  19.  
  20. void Threadings::runAlgoMain()
  21. {
  22. runAlgoMain();
  23. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include infusion.cpp
  2. #include "threadings.h"
  3. Infusion::Infusion(QWidget *parent) :
  4. QWidget(parent),
  5. ui(new Ui::Infusion)
  6. {
  7. QThread cThread;
  8. Threadings cThreadings;
  9. cThreadings.DoSetup(cThread);
  10. cThreadings.moveToThread(&cThread);
  11. cThread.start();
  12. }
To copy to clipboard, switch view to plain text mode 

Am i doing threading right ? Please help