Why did the program crash on QDateTime?
-
Kit: Windows 10 64bit , Qt 5.14.2 MinGW-64bit
Codes :int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); const int NUM = 8; std::thread threads[NUM]; for (int i = 0; i < NUM; i++) { threads[i] = std::thread( []() { for (int i = 0; i < 100000; i++) { QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"); } }); } for (int i = 0; i < NUM; i++) { if (threads[i].joinable()) threads[i].join(); } return 0; }Stack:

-
Unfortunately, QCalendar currently cannot be accessed from mulltiple threads: https://bugreports.qt.io/browse/QTBUG-84575
As you can see from your debugger's stack trace,
QDateTime::toString()calls QCalendar functions, so you currently cannot callQDateTime::toString()from multiple threads. -
Unfortunately, QCalendar currently cannot be accessed from mulltiple threads: https://bugreports.qt.io/browse/QTBUG-84575
As you can see from your debugger's stack trace,
QDateTime::toString()calls QCalendar functions, so you currently cannot callQDateTime::toString()from multiple threads. -
Unfortunately, QCalendar currently cannot be accessed from mulltiple threads: https://bugreports.qt.io/browse/QTBUG-84575
As you can see from your debugger's stack trace,
QDateTime::toString()calls QCalendar functions, so you currently cannot callQDateTime::toString()from multiple threads.@JKSH said in Why did the program crash on QDateTime?:
Unfortunately, QCalendar currently cannot be accessed from mulltiple threads: https://bugreports.qt.io/browse/QTBUG-84575
The problem is that this bug propagates all over the place. It's not just
QCalendar, it breaksQDateTime's reentrancy, which breaks the SQL driver(s) reentrancy and so on, and so on ... the possibilities are endless.