Re: Exception handling C++ and Qt
Let's try this again...
void Widget::examinedata()
{
//let the user select a starting byte and the dump the contents
//of a byte, word and longword. The text is already displayed
char *ptr;
unsigned char byteval;
short wordval;
unsigned short uwordval;
long longval;
unsigned long ulongval;
QDateTime dt;
QString sDate;
ptr = hexdump->pointerval() + buffer; //buffer pointer is calculated
when the user
memcpy(&byteval,ptr,1); //releases the mouse button
wordval = 0; uwordval = 0;
longval = 0; ulongval = 0;
//get word and longword values so long as we're not past the end of the
buffer
if ((long)hexdump->pointerval() <= (long)(fsize - sizeof(wordval)))
{
memcpy(&wordval,ptr,sizeof(wordval));
memcpy(&uwordval,ptr,sizeof(uwordval));
}
if ((long)hexdump->pointerval() <= (long)(fsize - sizeof(longval)))
{
memcpy(&longval,ptr,sizeof(longval));
memcpy(&ulongval,ptr,sizeof(ulongval));
}
if ((long)hexdump->pointerval() <= (long)(fsize - sizeof(dt)))
{
memcpy(&dt,ptr,sizeof(dt));
}
sDate = "invalid";
try
{
qDebug() << "before isValid";
if (dt.isValid())
sDate = dt.toString("dd/MM/yyyy hh:mm");
qDebug() << "after isValid";
}
catch(...)
{
sDate = "Error!!";
}
//output the results
lbldata->setText(QString("<html>Char: %1<br><br>") .arg(byteval) +
QString("sWord: %1<br>") .arg(wordval) +
QString("uWord: %1<br><br>") .arg(uwordval) +
QString("sLong: %1<br>") .arg(longval) +
QString("uLong: %1") .arg(ulongval) +
QString("sDate: %1") .arg(sDate) +
QString("</html>")
);
}