Hi (sorry for my english).. i'm new in the forum, and this is my first post,(shame.. is a question) .. I'm working in a console application that use OpenGL to show a Camera view, and i add Qt to use the really awesome class QThread (C++) ..But i have some problems.. here my code and then the description:
Qt Code:
  1. #ifndef CONTADOR_REGISTER_H
  2. #define CONTADOR_REGISTER_H
  3.  
  4. #include <QThread>
  5. #include <QObject>
  6. #include <QDebug>
  7.  
  8. #include "database.h"
  9.  
  10. class ContadorRegister : public QThread
  11. {
  12. Q_OBJECT
  13. public:
  14. ContadorRegister(User user, UserID id);
  15. void run();
  16. private:
  17. User user;
  18. UserID uid;
  19. public slots:
  20. void fin(){ qDebug()<<"Thread ended"; }
  21.  
  22. };
  23.  
  24. #endif // CONTADOR_REGISTER_H
  25.  
  26. //And the implementation in contador_register.cpp
  27. #include "contador_register.h"
  28.  
  29. ContadorRegister::ContadorRegister(const User userG, UserID id){
  30. this->uid = id;
  31. this->user = userG;
  32. }
  33.  
  34.  
  35. void ContadorRegister::run(){
  36. this->setTerminationEnabled(true);
  37. QObject::connect(this,SIGNAL(finished()),this,SLOT(fin()));
  38. int dir=0;
  39. //Some calculations
  40. //Registro en BD
  41. if(dir==1){
  42. QString sql="INSERT INTO registro VALUES(";
  43. sql.append("NOW())");
  44. DB->insertar(sql);
  45. }
  46. this->finished();
  47. }
To copy to clipboard, switch view to plain text mode 

And finally the function where i call this thread.
This is a callback function .. this function trigger up every time of a user is saw for the camera.

Qt Code:
  1. ContadorRegister* cr = new ContadorRegister(generator,nId);
  2. cr->start();
  3. qDebug()<<"Starting" << cr->currentThreadId();
  4.  
  5. if(cr->isRunning()){
  6. qDebug()<<"Still Running "<<cr->currentThreadId();
  7. }else
  8. {
  9. qDebug()<<"Ended "<<cr->currentThreadId();
  10. }
To copy to clipboard, switch view to plain text mode 

Well .. the problem is.. i this function (or another in the main) i need to check if the QThread is running or not...

And beside.. if the thread don't die.. the memory consume will be big... this application will run 24hrs 7days..

Any idea?

Thanks