I am creating a "new" struct object and sending the pointer through a signal about 100 times per second. This signal is connected to a slot in a different thread. If I run the app with the first code snip-it, the data is corrupted between 0 and 10 000 sent signals. If I run it with the second code snip-it (I just wanted to do a little debugging) it never gets corrupted.

Any Ideas why this is happening? and if there is a nicer solution than using a conditional statement?

Corrupted after some time:
Qt Code:
  1. struct MyStruct
  2. {
  3. MyStruct(unsigned int handle, std::string const& aName, std::string const& bName) :
  4. _handle(handle),
  5. _aName(aName),
  6. _bName(bName)
  7. {
  8. }
  9.  
  10. unsigned int _handle;
  11. std::string _aName;
  12. std::string _bName;
  13. };
To copy to clipboard, switch view to plain text mode 

Doesn't get corrupted:
Qt Code:
  1. struct MyStruct
  2. {
  3. MyStruct(unsigned int handle, std::string const& aName, std::string const& bName) :
  4. _handle(handle),
  5. _aName(aName),
  6. _bName(bName)
  7. {
  8. if(_bName.at(0) < 'A' || _bName.at(0) > 'z')
  9. {
  10. qDebug() << "ERROR: " << _bName.c_str();
  11. }
  12. if(_aName.size() > 0 && (_aName.at(0) < 'A' || _aName.at(0) > 'z'))
  13. {
  14. qDebug() << "ERROR: " << _aName.c_str();
  15. }
  16. }
  17.  
  18. unsigned int _handle;
  19. std::string _aName;
  20. std::string _bName;
  21. };
To copy to clipboard, switch view to plain text mode