Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Why did the program crash on QDateTime?

    General and Desktop
    3
    4
    188
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      Tancen last edited by Tancen

      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:
      微信截图_20201225135234.png

      1 Reply Last reply Reply Quote 0
      • JKSH
        JKSH Moderators last edited by

        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 call QDateTime::toString() from multiple threads.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        T kshegunov 2 Replies Last reply Reply Quote 4
        • T
          Tancen @JKSH last edited by

          @JKSH Thanks, I don't conscious of this is a bug.

          1 Reply Last reply Reply Quote 0
          • kshegunov
            kshegunov Moderators @JKSH last edited by

            @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 breaks QDateTime's reentrancy, which breaks the SQL driver(s) reentrancy and so on, and so on ... the possibilities are endless.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply Reply Quote 2
            • First post
              Last post