Results 1 to 3 of 3

Thread: Using QCustomEvent in QThread

  1. #1
    Join Date
    Jan 2006
    Posts
    9
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Using QCustomEvent in QThread

    Hi! I'am sorry to my english.
    Why code line
    Qt Code:
    1. delete dbe;
    To copy to clipboard, switch view to plain text mode 
    cause for Segmentatuon fault, if this line to follow after code
    Qt Code:
    1. DBEvent* dbe = new DBEvent(n,x,y);
    2. QApplication::postEvent( receiver, dbe );
    3. ...
    4. msleep(1);
    5. //delete dbe;
    To copy to clipboard, switch view to plain text mode 
    Аbove code from within QThread::run().

    The class DBEven implementation:
    Qt Code:
    1. class DBEvent : public QCustomEvent {
    2. public:
    3. DBEvent( int n_, double* px_, double* py_) :
    4. QCustomEvent( 65432 ), n(n_), px(px_), py(py_) {
    5. }
    6. ...
    7. private:
    8. int n;
    9. double *px;
    10. double *py;
    11. };
    To copy to clipboard, switch view to plain text mode 

    Who killed CustomEvent?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using QCustomEvent in QThread

    The events are automaticaly deleted when processed:
    http://doc.trolltech.com/3.3/qcustomevent.html
    Qt Code:
    1. ColorChangeEvent* ce = new ColorChangeEvent(blue);
    2. QApplication::postEvent( receiver, ce ); // Qt will delete it when done
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    109
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Using QCustomEvent in QThread

    This is documented:
    QCoreApplication::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.

Similar Threads

  1. QFile locks debug environment in QThread
    By nickolais in forum Qt Programming
    Replies: 1
    Last Post: 12th February 2009, 08:20
  2. QThread and QTcpSocket
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2008, 14:06
  3. Spawn a QThread in another QThread
    By david.corinex in forum Qt Programming
    Replies: 2
    Last Post: 19th December 2007, 13:54
  4. QThread exec proplem to stop...
    By patrik08 in forum Qt Programming
    Replies: 29
    Last Post: 21st May 2007, 08:51
  5. Is it possible to create a QThread without inheriting ?
    By probine in forum Qt Programming
    Replies: 6
    Last Post: 23rd March 2006, 23:51

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.