Passing data in PostEvent
why is this not working? I do the usual PostEvent call to update the UI from another thread. It works perfectly until I comment free(buffer) back in. The destructor is called by the system (I assume after event() has consumed the event) but trying to free the buffer causes an access violation. leaving it out causes memory leaks.
Code:
class FrameEvent
: public QEvent{
public:
~FrameEvent()
{
free(buffer);
}
unsigned char * buffer;
};
Re: Passing data in PostEvent
How was the buffer allocated?
Does it also get freed elsewhere?
Cheers,
_
Re: Passing data in PostEvent
I suggest using QPointer instead of the standard pointer. It is much safer.
Re: Passing data in PostEvent
Quote:
Originally Posted by
Lesiok
I suggest using QPointer instead of the standard pointer. It is much safer.
You probably meant QSharedPointer or QScopedPointer, as QPointer is for QObjects.
For a byte array it might even be better to go for QByteArray though.
It still depends on how the memory is allocated or used in the first place.
E.g. memory allocated with "new" must be free with "delete", while memory allocated with "malloc" must be freed with "free", etc.
Cheers,
_
Re: Passing data in PostEvent
Quote:
Originally Posted by
anda_skoa
You probably meant QSharedPointer or QScopedPointer, as QPointer is for QObjects.
For a byte array it might even be better to go for QByteArray though.
Of course.