Results 1 to 17 of 17

Thread: Architecture problem using threads, custom events and signals/slots

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Architecture problem using threads, custom events and signals/slots

    I don't know the "good-way-programming" with thread so I don't know if it is correct to do the way I do. I didn't it was a problem to create an instance in one thread and use it in another ... I didn't knew since it brings me trouble with data sharing and so on
    Last edited by yellowmat; 6th March 2006 at 20:46. Reason: Completion and modification

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Architecture problem using threads, custom events and signals/slots

    Quote Originally Posted by yellowmat
    I don't know the "good-way-programming" with thread so I don't know if it is correct to do the way I do. I didn't it was a problem to create an instance in one thread and use it in another ...
    It looks like QextSerialPort has some protection against problems with multiple threads, but still I think that you should instantiate it in CSerialDataFrameDecoder::run().

    I'm not sure why did you split the decoding in two parts (CSerialDataFrameDecoder::run() and CSerialPort::customEvent()). If you create a separate thread for decoding why don't you let it do the whole job?

    Another thing is that in several places you create a temporary frame object just to copy it later:
    Qt Code:
    1. CSerialDataFrame aFrame;
    2. aFrame.setSerialDataFrameValue(frame);
    3. aFrame.setSerialDataFrameStatus(CSerialDataFrame::SerialDataFrameStatusIncompleteHasJustTheEndingPart);
    4. this->serialDataFrameDecoded(aFrame);
    To copy to clipboard, switch view to plain text mode 
    Wouldn't it be easier to allocate that CSerialDataFrame on the heap?
    Qt Code:
    1. CSerialDataFrame *aFrame = new CSerialDataFrame( QDeepCopy<QString>( frame ),
    2. CSerialDataFrame::SerialDataFrameStatusIncompleteHasJustTheEndingPart );
    3. serialDataFrameDecoded( aFrame );
    4.  
    5. //...
    6.  
    7. void CSerialDataFrameDecoder::serialDataFrameDecoded( CSerialDataFrame * frame )
    8. {
    9. // Allocate some memory for the custom event
    10. QCustomEvent* ce = new QCustomEvent( 1002, data );
    11.  
    12. // Send the event
    13. QApplication::postEvent( objectOwner, ce );
    14. // The allocated memory for the custum event is freed by Qt so the receiver neither the sender MUST NOT free it
    15. }
    To copy to clipboard, switch view to plain text mode 

    And the last thing --- you should define that "1002" as constant.

  3. The following user says thank you to jacek for this useful post:

    yellowmat (7th March 2006)

  4. #3
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Architecture problem using threads, custom events and signals/slots

    Ok.

    I'll do all those changes in CSerialDataFrameDecoder and keep you informed.

    Thanks for your help, it is precious.

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.