A
Ady
Hi,
I'm not sure if this is the place to ask this so please bear with me just in
case you are able to help.
I am writing an application using Nokias Qt Creator on Windows and C++
(because it's free) which is intended to examine the contents of a data file
byte-by-byte and generating an output of byte, short int and long int values
depending on the position of what the user has selected. All this works.
However, when I try to add a QDateTime variable to the program and I move
the relevant data segment to the variable, then try to use the .isValid()
function I always get an access violation which Qt can't handle.
I know I'm doing something daft here, and I'm quite new to C++. If anyone
can point me in the right direction it would be appreciated.
I am posting the relevant section of code.
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 { if
(dt.isValid()) sDate = dt.toString("dd/MM/yyyy hh:mm"); }
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>") );}
I'm not sure if this is the place to ask this so please bear with me just in
case you are able to help.
I am writing an application using Nokias Qt Creator on Windows and C++
(because it's free) which is intended to examine the contents of a data file
byte-by-byte and generating an output of byte, short int and long int values
depending on the position of what the user has selected. All this works.
However, when I try to add a QDateTime variable to the program and I move
the relevant data segment to the variable, then try to use the .isValid()
function I always get an access violation which Qt can't handle.
I know I'm doing something daft here, and I'm quite new to C++. If anyone
can point me in the right direction it would be appreciated.
I am posting the relevant section of code.
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 { if
(dt.isValid()) sDate = dt.toString("dd/MM/yyyy hh:mm"); }
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>") );}