Hi all,

I am running into a problem which can be best descrivbed as below:

I have a QT4 C++ program which calls a matlab created library (compiled with MSVC2008). I am using MSVC2008 as IDE on Windows XP and the program is being compiled with MSVC2008 as well. I followed all the instructions regarding the dll compilation and how to integrate it to my code (MCR installation, etc.). Now, I could compiled and run it but got nothing from the MATLAB routine. The following is the key code.
Qt Code:
  1. DisplayWidget::DisplayWidget(QWidget *parent)
  2. : QWidget(parent)
  3. , pointsPerBlock(6400)
  4. {
  5. QString titleText;
  6. ui = new Ui::DisplayWidget();
  7. ui->setupUi(this);
  8.  
  9. ...
  10. [COLOR="#FF0000"]
  11. // I Initialize the mcl application and lib in the constructor
  12. [/COLOR]
  13. if (!mclInitializeApplication(NULL,0))
  14. {
  15. qDebug() << "Fail to initialize application!";
  16. return;
  17. }
  18. if (!libpulseanalysisInitialize())
  19. {
  20. qDebug() << "Fail to initialize library!";
  21. return;
  22. }
  23.  
  24. ...
  25. }
  26.  
  27. DisplayWidget::~DisplayWidget()
  28. {
  29. [COLOR="#FF0000"]
  30. // Terminate application and lib in destroyer
  31. [/COLOR]
  32. libpulseanalysisTerminate();
  33. mclTerminateApplication();
  34. delete ui;
  35. }
To copy to clipboard, switch view to plain text mode 

I tried to call the matlab routine in a slot function
Qt Code:
  1. void DisplayWidget::analyseData(void)
  2. {
  3. QRectF rect(d_display->getZoomerRect());
  4. //qDebug() << static_cast<int>(rect.left());
  5. //qDebug() << static_cast<int>(rect.width());
  6. QByteArray data(d_data.mid(static_cast<int>(rect.left()),
  7. static_cast<int>(rect.width()) * sizeof(double)));
  8. qDebug() << data.size();
  9. int dataLength = data.size();
  10. qDebug() << dataLength;
  11. QDataStream dataStream(&data, QIODevice::ReadOnly);
  12. dataStream.setByteOrder(QDataStream::ByteOrder(QDataStream::LittleEndian));
  13. dataStream.setFloatingPointPrecision(QDataStream::DoublePrecision);
  14. double *pData = new double(dataLength);
  15. for (int i = 0; i < dataLength; i++)
  16. {
  17. dataStream >> *(pData + i);
  18. }
  19. int downSamplingFactor = 5;
  20. int windowWidth = 500;
  21.  
  22. //mxArray *sig = NULL;
  23. //mxArray *downsampling_factor = NULL;
  24. //mxArray *window_width = NULL;
  25.  
  26.  
  27. //sig = mxCreateDoubleMatrix(1, dataLength, mxREAL);
  28. //memcpy(mxGetPr(sig), pData, sizeof(double) * dataLength);
  29.  
  30. //downsampling_factor = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
  31. //memcpy(mxGetPr(downsampling_factor), &downSamplingFactor, sizeof(double));
  32.  
  33. //window_width = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
  34. //memcpy(mxGetPr(window_width), &window_width, sizeof(double));
  35.  
  36. mwArray sig(1, dataLength, mxDOUBLE_CLASS);
  37. sig.SetData(pData, dataLength);
  38. mwArray downsampling_factor(1, 1, mxINT32_CLASS);
  39. downsampling_factor.SetData(&downSamplingFactor, 1);
  40. mwArray window_width(1, 1, mxINT32_CLASS);
  41. window_width.SetData(&windowWidth, 1);
  42. mwArray edge_time;
  43.  
  44. pulse_analysis(1, edge_time, sig, downsampling_factor, window_width);
  45.  
  46. qDebug() << edge_time.ElementSize();
  47.  
  48. //int r = mxGetM(edge_time);
  49. //int c = mxGetN(edge_time);
  50.  
  51. //qDebug() << r;
  52. //qDebug() << c;
  53. }
To copy to clipboard, switch view to plain text mode 
I placed a break point on the pulse_analysis function. After the program reached the break point, I press the F10, then the program enter into the
Qt Code:
  1. QHashData::Node *QHashData::nextNode(Node *node)
To copy to clipboard, switch view to plain text mode 
and stopped on the following instruction.
Qt Code:
  1. int start = (node->h % d->numBuckets) + 1;
To copy to clipboard, switch view to plain text mode 
The content in the output window is:
First-chance exception at 0x670a539d (QtCored4.dll) in XXXX.exe: 0xC0000094: Integer division by zero.
Unhandled exception at 0x670a539d (QtCored4.dll) in XXXX.exe: 0xC0000094: Integer division by zero.
I didn't know why the application throw this error message. I wanted to investigate where the error come from, but I didn't know how to debug such an application. Could anybody give me some help?