If there are multiple consumers of your data then signal/slots is the correct mechanism. If there is only one consumer then there is little point in using signal/slot - just use direct method calls or QMetaObject::invokeMethod to jump thread contexts. You do not need to send the actual data through a signal, though!
MyDataStructure data;
// set up data
emit DataReady(data); // bad
MyDataStructure data;
// set up data
emit DataReady(data); // bad
To copy to clipboard, switch view to plain text mode
MyDataStructure data;
// set up data
// finished writing to data - move it to some 'safe for reading' area
MyDataStructure* dataPointerThatIsSafeForSharing = MoveToSharedReadingBuffer(data);
emit DataReady(dataPointerThatIsSafeForSharing); // good. signal signature is void DataReady(MyDataStructure const * ptr); so data is read only
MyDataStructure data;
// set up data
// finished writing to data - move it to some 'safe for reading' area
MyDataStructure* dataPointerThatIsSafeForSharing = MoveToSharedReadingBuffer(data);
emit DataReady(dataPointerThatIsSafeForSharing); // good. signal signature is void DataReady(MyDataStructure const * ptr); so data is read only
To copy to clipboard, switch view to plain text mode
you can optimise this version to only create one MyDataStructure.
Bookmarks