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. Access to components of UI from the function of QtConcurrent::run(foo)
Forum Updated to NodeBB v4.3 + New Features

Access to components of UI from the function of QtConcurrent::run(foo)

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.8k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MohammadReza
    wrote on last edited by
    #1

    Hello friends,

    I want to access to components of UI (like as QLineEdit, QLabel, QTableView, etc) from the "foo" function in QtConcurrent::run(foo).
    But I cant, because the component must be static variable and I dont want.
    How can I access to them?

    Thanks a lot.
    Ya Ali.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      No, you can't because manipulating GUI element outside the main thread is not allowed. What you can do however is use signals and slots to communicate with the GUI stuff

      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
      0
      • M Offline
        M Offline
        MohammadReza
        wrote on last edited by
        #3

        Hi dear SGaist,
        Thanks for your response.

        I searched and most of uses said signal and slot must be used.
        I implemented this approach but did not work! Because I can`t emit the signal from the thread (because signal function is not static).
        How can I do that? May you give a simple code?

        Thanks.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You can use a QObject wrapper class that will call the static function and then emit the signal needed

          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
          0
          • M Offline
            M Offline
            MohammadReza
            wrote on last edited by
            #5

            Can you give me a simple code example?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Wait, this might be a complication you don't need, did you took a look at the QFutureWatcher class ?

              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
              0

              • Login

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