Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is thread-safe?
QtWS25 Last Chance

What is thread-safe?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 4.9k Views
  • 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.
  • W Offline
    W Offline
    windyweather
    wrote on last edited by
    #1

    I've seen some references to thread-safety in various places, but I can't find the documentation in the docs for 4.7.
    I'm starting here and looking for thread-safety topics with no luck.
    I expected to see a "best practices" note about threads or something.
    Can someone help me out starting here:
    http://doc.qt.nokia.com/4.7/index.html

    I'm doing a file management program that is building content in a QTreeWidget and I'd like to build the QTreeWidgetItems in another thread and add them to the widget there while the rest of the GUI is alive. That would be the best case. I've seen that "Containers are thread-safe" but I don't want to make unwarranted assumptions about the GUI without reviewing the docs.

    Thanks,
    Windy

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Th Qt UI stuff MUST be used inside the main thread, Only data classes are (some of them) thread safe. If you are doing some file management, I would suggest using a model view approach and not a QTreeWidget approach. It'smuch more optimizable...

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DenisKormalev
        wrote on last edited by
        #3

        Agreed with Gerolf, model-view will give you much more flexible solution. Also maybe it will be ok to you to use QFileSystemModel instead of writing your own.

        1 Reply Last reply
        0
        • ZlatomirZ Offline
          ZlatomirZ Offline
          Zlatomir
          wrote on last edited by
          #4

          About documentation, this "link":http://doc.qt.nokia.com/4.7/qt-basic-concepts.html is pure gold ;) in my opinion
          You have there links to both: Model-View and Threading + other Qt concepts

          https://forum.qt.io/category/41/romanian

          1 Reply Last reply
          0
          • W Offline
            W Offline
            windyweather
            wrote on last edited by
            #5

            Thanks. My application is not exactly a FileSystemModel, but I'll have another look at the Model View stuff.

            Well shucks. Bummer that the containers of the View / widget are not thread-safe.

            Thanks,
            ww

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              You can create class that will inherit FSM and change something you needed there. Maybe it will save you some time in developing your app.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                It's perfectly ok to have some worker threads in the background, that send their data via signal/slot connections to the model. That's the way the Trolls do it in the QFileSystemModel - have a look in the sources (start with src/gui/dialogs/qfileinfogatherer.cpp).

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved