Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved QStorageInfo and QPair Qt Reentrancy

    General and Desktop
    2
    6
    1187
    Loading More Posts
    • 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.
    • C
      Crag_Hack last edited by

      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!

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        std::pair works mostly the same as QPair.

        What exactly do you want to pass to your worker thread ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • C
          Crag_Hack last edited by

          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. :)

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • C
              Crag_Hack last edited by

              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?

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Yes it should be.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post