Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why did the program crash on QDateTime?
Forum Updated to NodeBB v4.3 + New Features

Why did the program crash on QDateTime?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 470 Views 2 Watching
  • 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 Offline
    T Offline
    Tancen
    wrote on last edited by Tancen
    #1

    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
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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 kshegunovK 2 Replies Last reply
      4
      • JKSHJ JKSH

        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.

        T Offline
        T Offline
        Tancen
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • JKSHJ JKSH

          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.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @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
          3

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved