PDA

View Full Version : Using QCustomEvent in QThread



Dmitry
6th January 2006, 23:35
Hi! I'am sorry to my english.
Why code line


delete dbe;

cause for Segmentatuon fault, if this line to follow after code


DBEvent* dbe = new DBEvent(n,x,y);
QApplication::postEvent( receiver, dbe );
...
msleep(1);
//delete dbe;

Аbove code from within QThread::run().

The class DBEven implementation:


class DBEvent : public QCustomEvent {
public:
DBEvent( int n_, double* px_, double* py_) :
QCustomEvent( 65432 ), n(n_), px(px_), py(py_) {
}
...
private:
int n;
double *px;
double *py;
};


Who killed CustomEvent?

Thanks.

yop
6th January 2006, 23:40
The events are automaticaly deleted when processed:
http://doc.trolltech.com/3.3/qcustomevent.html


ColorChangeEvent* ce = new ColorChangeEvent(blue);
QApplication::postEvent( receiver, ce ); // Qt will delete it when done

dimitri
7th January 2006, 12:43
This is documented:

QCoreApplication::postEvent (http://doc.trolltech.com/4.1/qcoreapplication.html#postEvent)
The event must be allocated on the heap since the post event queue will take ownership of the event and delete it once it has been posted. It is not safe to modify or delete the event after it has been posted.