PDA

View Full Version : How to debug the matlab routine in QT4 application



honestapple
29th August 2013, 04:12
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.


DisplayWidget::DisplayWidget(QWidget *parent)
: QWidget(parent)
, pointsPerBlock(6400)
{
QString titleText;
ui = new Ui::DisplayWidget();
ui->setupUi(this);

...

// I Initialize the mcl application and lib in the constructor

if (!mclInitializeApplication(NULL,0))
{
qDebug() << "Fail to initialize application!";
return;
}
if (!libpulseanalysisInitialize())
{
qDebug() << "Fail to initialize library!";
return;
}

...
}

DisplayWidget::~DisplayWidget()
{

// Terminate application and lib in destroyer

libpulseanalysisTerminate();
mclTerminateApplication();
delete ui;
}


I tried to call the matlab routine in a slot function


void DisplayWidget::analyseData(void)
{
QRectF rect(d_display->getZoomerRect());
//qDebug() << static_cast<int>(rect.left());
//qDebug() << static_cast<int>(rect.width());
QByteArray data(d_data.mid(static_cast<int>(rect.left()),
static_cast<int>(rect.width()) * sizeof(double)));
qDebug() << data.size();
int dataLength = data.size();
qDebug() << dataLength;
QDataStream dataStream(&data, QIODevice::ReadOnly);
dataStream.setByteOrder(QDataStream::ByteOrder(QDa taStream::LittleEndian));
dataStream.setFloatingPointPrecision(QDataStream:: DoublePrecision);
double *pData = new double(dataLength);
for (int i = 0; i < dataLength; i++)
{
dataStream >> *(pData + i);
}
int downSamplingFactor = 5;
int windowWidth = 500;

//mxArray *sig = NULL;
//mxArray *downsampling_factor = NULL;
//mxArray *window_width = NULL;


//sig = mxCreateDoubleMatrix(1, dataLength, mxREAL);
//memcpy(mxGetPr(sig), pData, sizeof(double) * dataLength);

//downsampling_factor = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
//memcpy(mxGetPr(downsampling_factor), &downSamplingFactor, sizeof(double));

//window_width = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
//memcpy(mxGetPr(window_width), &window_width, sizeof(double));

mwArray sig(1, dataLength, mxDOUBLE_CLASS);
sig.SetData(pData, dataLength);
mwArray downsampling_factor(1, 1, mxINT32_CLASS);
downsampling_factor.SetData(&downSamplingFactor, 1);
mwArray window_width(1, 1, mxINT32_CLASS);
window_width.SetData(&windowWidth, 1);
mwArray edge_time;

pulse_analysis(1, edge_time, sig, downsampling_factor, window_width);

qDebug() << edge_time.ElementSize();

//int r = mxGetM(edge_time);
//int c = mxGetN(edge_time);

//qDebug() << r;
//qDebug() << c;
}

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
QHashData::Node *QHashData::nextNode(Node *node)
and stopped on the following instruction.

int start = (node->h % d->numBuckets) + 1;
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?

Santosh Reddy
29th August 2013, 08:00
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.

honestapple
29th August 2013, 08:43
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

bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
and pointed to


bool returnValue;
QT_TRY {
returnValue = notify(receiver, event);
} QT_CATCH (...) {
--threadData->loopLevel;
QT_RETHROW;
}

What does this mean?