PDA

View Full Version : Using a QMutex as a static class member



emostar
14th June 2009, 03:19
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!

seim
14th June 2009, 22:37
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?

emostar
15th June 2009, 14:48
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.