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:
struct MyStruct
{
MyStruct(unsigned int handle, std::string const& aName, std::string const& bName) :
_handle(handle),
_aName(aName),
_bName(bName)
{
}
unsigned int _handle;
std::string _aName;
std::string _bName;
};
struct MyStruct
{
MyStruct(unsigned int handle, std::string const& aName, std::string const& bName) :
_handle(handle),
_aName(aName),
_bName(bName)
{
}
unsigned int _handle;
std::string _aName;
std::string _bName;
};
To copy to clipboard, switch view to plain text mode
Doesn't get corrupted:
struct MyStruct
{
MyStruct(unsigned int handle, std::string const& aName, std::string const& bName) :
_handle(handle),
_aName(aName),
_bName(bName)
{
if(_bName.at(0) < 'A' || _bName.at(0) > 'z')
{
qDebug() << "ERROR: " << _bName.c_str();
}
if(_aName.size() > 0 && (_aName.at(0) < 'A' || _aName.at(0) > 'z'))
{
qDebug() << "ERROR: " << _aName.c_str();
}
}
unsigned int _handle;
std::string _aName;
std::string _bName;
};
struct MyStruct
{
MyStruct(unsigned int handle, std::string const& aName, std::string const& bName) :
_handle(handle),
_aName(aName),
_bName(bName)
{
if(_bName.at(0) < 'A' || _bName.at(0) > 'z')
{
qDebug() << "ERROR: " << _bName.c_str();
}
if(_aName.size() > 0 && (_aName.at(0) < 'A' || _aName.at(0) > 'z'))
{
qDebug() << "ERROR: " << _aName.c_str();
}
}
unsigned int _handle;
std::string _aName;
std::string _bName;
};
To copy to clipboard, switch view to plain text mode
Bookmarks