Results 1 to 3 of 3

Thread: Using a QMutex as a static class member

  1. #1
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Using a QMutex as a static class member

    Hello,

    I have a class that does it's work in a separate thread, I was using a class member QMutex to provide a mutex around the code that can be called by both the main thread and the worker thread.

    Now, I want to have a second instance of the same class, so it will need to have a mutex around some codes that is shared between both instances of the class. So I made it a static class member. I sometimes experience a crash in QMutex::lock(), so I was wondering if my design is flawed. And if so, what is the proper way of doing this?

    If there is no design flaw, then it is just a bug, which I'll have to look into. But I was starting to get worried that the design may be flawed

    Thanks!

  2. #2
    Join Date
    Dec 2008
    Posts
    29
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Using a QMutex as a static class member

    Strange.. And what is it doing when you declare it as a static object in some class method returning QMutex & or *? Can you show an example of your declaration/definition of mentioned static item?

  3. #3
    Join Date
    Jun 2009
    Posts
    10
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using a QMutex as a static class member

    Apparently I had a DB connection that was being run from a different thread than it was connected from. Using QtCreator to debug this issue didn't really give a good stack trace though.

    It appears my multi-threaded design is working now! Thanks.

Similar Threads

  1. Replies: 22
    Last Post: 8th October 2008, 13:54
  2. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  3. Replies: 4
    Last Post: 19th March 2008, 17:47
  4. Replies: 2
    Last Post: 16th March 2007, 09:04
  5. Accessing to a static variable from the same class
    By xgoan in forum General Programming
    Replies: 6
    Last Post: 5th March 2007, 10:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.