Solved QStorageInfo and QPair Qt Reentrancy
-
Hi both QStorageInfo and QPair are not listed as Qt reentrant in the online API docs. I was previously using these in a worker thread but am feeling inclined to find other ways of doing things due to the lack of Qt reentrancy. As long as you only use these classes in one thread only (exclusively the worker thread or gui thread) is that safe behavior? Is the STL pair class qt reentrant and safe to use in a worker thread with its own object instances? Can I safely use QStorageInfo in my main thread to retrieve what I need (free space on drives) then pass that information to my worker thread? Anything else to know?
Thanks! -
Hi,
std::pair works mostly the same as QPair.
What exactly do you want to pass to your worker thread ?
-
Thanks SGaist. Is std::pair going to be qt reentrant? I am just passing free space amounts stored in integers as determined from QStorageInfo. So only the GUI thread is using the QStorageInfo object. Is this safe? Is this in general safe for any non-reentrant class to be accessed as long as it's only in the main gui thread? How about if only in the worker thread? I was trying the win32 API for the same but it's a hideous syntactical nightmare and it's giving me attitude. :)
-
There's no "Qt reentrant" concept. Qt is a C++ framework so the same rules applies to Qt as any other piece of code when dealing with threads.
There's nothing to worry about when accessing something if you do it cleanly. An object that is created in one thread and is only accessed in that thread doesn't need to be something special. It's when you start to access or modify an object from several threads that you need to start worrying about side-effects.
-
So then is it safe to use QStorageInfo in a worker thread even though it's not reentrant as long as you only use it there?
-
Yes it should be.