I'm using QT 5.1.0 -rc2 + OpenCV 2.4 with primesensor kinect

Here's my code written below.
My problem is when I add
kinectcapture = new camera(1);
in mainwindow.cpp line 32
the program just unexpected ternimated.

Did I miss something?

Thanks.

camera.h
Qt Code:
  1. #ifndef CAMERA_H
  2. #define CAMERA_H
  3.  
  4.  
  5. #include <QThread>
  6. #include <opencv.hpp>
  7. #include "iostream"
  8. #include "QImage"
  9.  
  10.  
  11. class camera : public QThread
  12. {
  13. Q_OBJECT
  14. public:
  15. //explicit camera(QObject *parent = 0);
  16. explicit camera(const int &data);
  17. ~camera();
  18. void stop();
  19. bool open_camera();
  20.  
  21. signals:
  22. void sendImage_ball(const QImage &img);
  23. void sendTrueDepthImage_ball(const cv::Mat &depthImg);
  24. void sendDepthImage_ball(const cv::Mat &depthImg);
  25. public slots:
  26. protected:
  27. void run();
  28.  
  29. private:
  30. cv::VideoCapture capture;
  31. cv::Mat img_cur;
  32. bool stopped;
  33. int datatype;
  34.  
  35. };
To copy to clipboard, switch view to plain text mode 

camera.cpp
Qt Code:
  1. #include "camera.h"
  2. #include "QDebug"
  3.  
  4. camera::camera(const int &data)
  5. {
  6. stopped=true;
  7. datatype = data;
  8. }
  9.  
  10. camera::~camera(){}
  11.  
  12. bool camera::open_camera(){
  13. return capture.open(CV_CAP_OPENNI);
  14. }
  15.  
  16. void camera::run(){
  17. if(!capture.isOpened())
  18. throw 1;
  19.  
  20. stopped=false;
  21. cv::Mat bgrImg;
  22. cv::Mat depthImg;
  23.  
  24. while(!stopped){
  25. if(!capture.grab())
  26. {
  27. std::cout<<"could not grab img!"<<endl;
  28. break;
  29. }
  30. else
  31. if( 1 && capture.retrieve( bgrImg, CV_CAP_OPENNI_BGR_IMAGE ) ) //capture bgr image
  32. if( 1 && capture.retrieve( depthImg, CV_CAP_OPENNI_DEPTH_MAP )) //capture depth image
  33. {
  34.  
  35. bgrImg.copyTo(img_cur); //copy the retrieve image to img_cur to proceed getCurrentImg() function
  36.  
  37. //converting Mat to QImage & display in Qlabel. Note that resolution must be set to prevent crash.
  38. cv::cvtColor(bgrImg, bgrImg, CV_RGB2RGBA);
  39. QImage DisplayImage_ball = QImage((const unsigned char*)(bgrImg.data), bgrImg.cols, bgrImg.rows, QImage::Format_RGB32);
  40. DisplayImage_ball=DisplayImage_ball.scaled(320,240,Qt::KeepAspectRatio);
  41. cv::cvtColor(bgrImg, bgrImg, CV_RGBA2RGB);
  42. //***********************************************************//
  43.  
  44. emit sendImage_ball(DisplayImage_ball);
  45. /*emit sendTrueDepthImage_ball(depthImg);
  46.   cv::Mat show_ball;
  47.   const float scaleFactor = 1.0f;
  48.   depthImg.convertTo( show_ball, CV_8UC1, scaleFactor );
  49.   emit sendDepthImage_ball(show_ball);*/
  50.  
  51.  
  52. }
  53.  
  54. }
  55. }
  56. void camera::stop(){
  57. stopped=true;
  58. }
To copy to clipboard, switch view to plain text mode 

mainwindow.h
Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include "camera.h"
  6. #include "QMessageBox"
  7.  
  8. namespace Ui {
  9. class MainWindow;
  10. }
  11.  
  12. class MainWindow : public QMainWindow
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. explicit MainWindow(QWidget *parent = 0);
  18. ~MainWindow();
  19.  
  20. private slots:
  21. void camera_show_update(const QImage &img);
  22. void on_openKinect_clicked();
  23.  
  24. private:
  25. Ui::MainWindow *ui;
  26. camera *kinectcapture;
  27. };
  28.  
  29. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

mainwindow.cpp
Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <iostream>
  4.  
  5.  
  6. MainWindow::MainWindow(QWidget *parent) :
  7. QMainWindow(parent),
  8. ui(new Ui::MainWindow)
  9. {
  10. ui->setupUi(this);
  11. kinectcapture =0;
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16. delete ui;
  17. if(kinectcapture){
  18. if(kinectcapture->isRunning()){
  19. kinectcapture->stop();
  20. kinectcapture->wait();
  21. delete kinectcapture;
  22. kinectcapture=0;
  23. }
  24. }
  25. }
  26.  
  27.  
  28.  
  29. void MainWindow::on_openKinect_clicked()
  30. {
  31. if(!kinectcapture){
  32. kinectcapture = new camera(1);
  33. }
  34. if(!kinectcapture->open_camera()){
  35. QMessageBox::warning(0, 0, "Can Not Open Cam");
  36. delete kinectcapture;
  37. kinectcapture=0;
  38. return;
  39. }
  40. kinectcapture->start();
  41. connect(kinectcapture,SIGNAL(sendImage_ball(QImage)),this,SLOT(camera_show_update(QImage)));
  42.  
  43. }
  44.  
  45. void MainWindow::camera_show_update(const QImage &img){
  46. ui->camera_show->setPixmap(QPixmap::fromImage(img));
  47. }
To copy to clipboard, switch view to plain text mode