Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Exception handling C++ and Qt

Thread Tools

Exception handling C++ and Qt

Michael Doubez
Posts: n/a
On 9 fév, 17:32, "Ady" <(E-Mail Removed)> wrote:
> "Michael Doubez" <(E-Mail Removed)> wrote in message
> >
> > news:(E-Mail Removed)....
> > On 8 fév, 17:37, "Ady" <(E-Mail Removed)> wrote:
> > [snip]
> >
> > > 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.

> >
> > No it is not. serialization is actually quite common.
> >
> > > I am posting the relevant section of code.

> >
> > [snip: code]
> >
> > The read code is not *sufficient, you should also post how you wrote
> > the file.
> >
> > Quickly reading the Qt documentation, I notice there is a QDataStream
> > class used for (de)serializing data. May be you can use it for writing/
> > > reading your file.

> >

> I feel some further explanation is required here. My program was originally
> intended to emulate the DUMP command from the OpenVMS operating system (my
> day job) on a Windows box. That bit of the program works so I decided to
> extend it allow the user to examine the contents of the file - ANY file. It
> may be a formatted file, it might not, it's whatever the user decides to
> look into. It's a tool I've found useful over the years.

> In answer to your post, there is therefore no writing of the original file.
> The file is selected by the user, opened, read into an appropriately sized
> buffer (malloc'd) and closed. The data is displayed in a hex dump window and
> a Ascii window (if a printable character). The user can then click or
> double-click on any byte displayed in the hex dump and the values of the
> various simple data types are displayed. I was hoping to add a date type but
> this is where I'm getting the access violations.

IIRC you have a binary dump of your memory.

> If there is a simple way of translating a 64-bit date 'type' under Qt I
> would really like to see it. It doesn't seem to have anything like the
> SYSTEMTIME and FILETIME structures that are available under VC++ 6.

SYSTEMTIME and FILETIME are C structure (POD in C++). As Richard
pointed out, QDateTime is not POD. Looking into QT headers, it seems
QtDate Time is composed of a QDate and a QTime but QDate, at least,
has virtual functions. This means the layout of the class may include
additional (RTTI) data and/or member layout reorganisation.

In short, the internal joined data is 64 bits (depending on compiler's
paddings) but there should also be a vtable pointer somewhere causing
the access violation you get; this is also plateform specific.

A solution could be to interpret your 64 bits into two unsigned int
and use them to initialise a QDateTime structure.

Reply With Quote
Posts: n/a

Thanks for the pointers, I'll look into it.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
signal handling and (structured) exception handling Peter C++ 34 10-17-2009 10:03 AM
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
How do I add exception-handling to this code and make sure it compiles and runs properly? C++ 4 06-20-2006 09:13 PM
SoapExtension for Global Exception handling; but prevent exception from propagating!! VSK ASP .Net Web Services 0 07-29-2003 05:39 PM