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. QMutexLocker with Q_GLOBAL_STATIC
Forum Updated to NodeBB v4.3 + New Features

QMutexLocker with Q_GLOBAL_STATIC

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 287 Views 1 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by beecksche
    #1

    Hi,
    i change my code to Qt 6 and get a compilation errer with QMutexLocker and a Q_GLOBAL_STATIC variable. The error occours not in Qt 5.15.

    Qt 6.5, MSVC2019, 64 bit, Win10

    Q_GLOBAL_STATIC(QMutex, mutex)
    
    ...
    
    void myFun() {
       QMutexLocker locker(&mutex); 
       //C2039, "lock" is not a member of "QGlobalStatic<QtGlobalStatic::Holder<`anonymous-namespace'::Q_QGS_m_mutex>>"
    }
    
    jsulmJ 1 Reply Last reply
    0
    • beeckscheB beecksche

      Hi,
      i change my code to Qt 6 and get a compilation errer with QMutexLocker and a Q_GLOBAL_STATIC variable. The error occours not in Qt 5.15.

      Qt 6.5, MSVC2019, 64 bit, Win10

      Q_GLOBAL_STATIC(QMutex, mutex)
      
      ...
      
      void myFun() {
         QMutexLocker locker(&mutex); 
         //C2039, "lock" is not a member of "QGlobalStatic<QtGlobalStatic::Holder<`anonymous-namespace'::Q_QGS_m_mutex>>"
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @beecksche said in QMutexLocker with Q_GLOBAL_STATIC:

      Q_GLOBAL_STATIC(QMutex, mutex)

      Why does it have to be global static?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      beeckscheB 1 Reply Last reply
      2
      • jsulmJ jsulm

        @beecksche said in QMutexLocker with Q_GLOBAL_STATIC:

        Q_GLOBAL_STATIC(QMutex, mutex)

        Why does it have to be global static?

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        @jsulm said in QMutexLocker with Q_GLOBAL_STATIC:

        Why does it have to be global static?

        Because of ... reasons ... No, you're absolutely right:

        QMutex mutex;
        ...
        void myFun() {
           QMutexLocker locker(&mutex); 
        }
        

        is totally sufficient. (And works by the way). Thanks

        1 Reply Last reply
        1
        • beeckscheB beecksche has marked this topic as solved on

        • Login

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