Crash in QDateTime::currentDateTime().toString()
-
Hi
I use QDateTime::currentDateTime() function in multiple threads. In each thread I create new QDateTime object on which I call currentDateTime().toString(). A crash happened and debbuger pointed to globalQDateTime.currentDateTime().toString(). I tried hundreds times but cannot reproduce the crash again. I cannot stop thinking what was the cause of the crash. QDateTime.currentDateTime is a static function and documentation says all functions in the QDateTime class are reentrant. As far as I know it is safe to use static function in secondary threads as long as it is a part of a new object instantiated in those threads. Any help please.
@//Main Thread:
QDateTime globalQDateTime;
globalQDateTime.currentDateTime().toString(); // crash here//Thread 1:
QDateTime tQDateTime; tQDateTime.daysTo(tQSslCertificate.expiryDate());//Thread 2:
QDateTime tQDateTime;
if (mQDateTime.addSec(3000) > tQDateTime.currentDateTime() ) ...@ -
Hi, the toString returns a QString so maybe you didn't handle the QString returned properly. That might also cause the segment error?
The threads may not be the problem.
greetz -
[quote author="Jeroentje@home" date="1339426002"]Hi, the toString returns a QString so maybe you didn't handle the QString returned properly. That might also cause the segment error?
The threads may not be the problem.
greetz[/quote]What are you talking about?! Ignoring return value of member function is legal! Absolutely legal in C++ meaning.
-
ENEEDMOREINFO. Could you post a stack trace of the crash? The code looks fine.
What I am not sure about is whether currentDateTime() is thread safe. If it uses a static object on QDateTime, it probably is not. You would need to serialize access to it then.