Results 1 to 4 of 4

Thread: mutex pointer in QMutexLocker

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default mutex pointer in QMutexLocker

    Hi,
    Can we use a mutex pointer inside QMutexLocker.For example:-

    MyClass.h

    Qt Code:
    1. QMutex *m_mutexPtr;
    To copy to clipboard, switch view to plain text mode 

    MyClass.cpp

    Qt Code:
    1. void myFunction() const
    2. {
    3. QMutexLocker locker(m_mutexPtr);
    4. ......
    5. }
    To copy to clipboard, switch view to plain text mode 

    Is it right way to use like this because the editor shows locker as unused variable,this happens only when i use mutex variable as Pointer.So is it wrong.I have attached image showing the editor.
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: mutex pointer in QMutexLocker

    QMutexLocker always works on a QMutex pointer.
    And yes, in most cases it is not used after instantiation (RAII idiom).

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: mutex pointer in QMutexLocker

    @anda:
    I understood that,but my doubt is why editor doesn't show anything(unused) if i use normal variable.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: mutex pointer in QMutexLocker

    No idea, the locker variable is still unused.
    No point in wasting any time on that.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 5th June 2013, 05:35
  2. Named Mutex in QT
    By doggrant in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2011, 12:11
  3. Mutex between two or more process
    By bred in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2010, 15:43
  4. Mutex unlock without locking it
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 23rd September 2010, 17:17
  5. Qthread mutex
    By dognzhe in forum Qt Programming
    Replies: 5
    Last Post: 18th May 2009, 05:46

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.