Results 1 to 3 of 3

Thread: How to debug the matlab routine in QT4 application

  1. #1
    Join Date
    Jan 2013
    Posts
    21
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default How to debug the matlab routine in QT4 application

    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?

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to debug the matlab routine in QT4 application

    Do a clean build of the application, and make sure that library and application are both built with same build configuration (i.e. both are debug builds), don't mix library release build with application debug build.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2013
    Posts
    21
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to debug the matlab routine in QT4 application

    Hi, Thank you for you reply. I compiled the dll in matlab using mcc with -g argument which generate debug information. But I still could not debug the application. When I pressed F11, the application entered
    Qt Code:
    1. bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
    To copy to clipboard, switch view to plain text mode 
    and pointed to
    Qt Code:
    1. bool returnValue;
    2. QT_TRY {
    3. returnValue = notify(receiver, event);
    4. } QT_CATCH (...) {
    5. --threadData->loopLevel;
    6. QT_RETHROW;
    7. }
    To copy to clipboard, switch view to plain text mode 
    What does this mean?

Similar Threads

  1. Replies: 1
    Last Post: 8th January 2014, 09:15
  2. Qt to Matlab (mat format) export data to Matlab .mat format -v4
    By windsword in forum Qt-based Software
    Replies: 4
    Last Post: 26th February 2013, 21:01
  3. Problem calling a routine with dynamicCall
    By franco.amato in forum Qt Programming
    Replies: 10
    Last Post: 10th May 2010, 18:59
  4. Problems with ACtiveQT in calling a routine
    By franco.amato in forum Qt Programming
    Replies: 0
    Last Post: 15th April 2010, 02:00
  5. Wierd behaviour in a slot routine
    By koenig in forum Newbie
    Replies: 7
    Last Post: 29th January 2010, 08:27

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.