MonsterPipe
March 15th, 2014, 04:05 AM
Hi,
I have a small QT application that needs to serialize some data periodically. I'm using a QThread with QMutex to protect my resources.
Here is the code I use inside my QThread. I don't know why but it writes no data at all in the file.
void CDataLogger::run(){ static GeneralInformations toto;
QDataStream out(m_File); // we will serialize the data into the file
while(MustRun) { m_Mutex->lock();
out << 45; out << 45; out << 45; out << 45; out << 45; out << 45; out << 45; out << 45;
m_Mutex->unlock(); this->sleep(1); }}
The m_File object is a QFile object pointer receive by the Main Thread. If I use the same code in the main thread, all data is written in the file but if I use it inside another thread, the file stays empty. Is it because the new thread needs some kind of privileges?
I need help on this. :)
Thank you in advance,
I have a small QT application that needs to serialize some data periodically. I'm using a QThread with QMutex to protect my resources.
Here is the code I use inside my QThread. I don't know why but it writes no data at all in the file.
void CDataLogger::run(){ static GeneralInformations toto;
QDataStream out(m_File); // we will serialize the data into the file
while(MustRun) { m_Mutex->lock();
out << 45; out << 45; out << 45; out << 45; out << 45; out << 45; out << 45; out << 45;
m_Mutex->unlock(); this->sleep(1); }}
The m_File object is a QFile object pointer receive by the Main Thread. If I use the same code in the main thread, all data is written in the file but if I use it inside another thread, the file stays empty. Is it because the new thread needs some kind of privileges?
I need help on this. :)
Thank you in advance,