Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How does threads access ui component

How does threads access ui component

Scheduled Pinned Locked Moved Mobile and Embedded
7 Posts 4 Posters 4.8k 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.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

    Hi

    My question is more on C++ language.

    I used one main window and one threads for my application in Freescale imx6.
    in the main window, i can use ui->setbutton(), to control the ui.successfully.

    I am not able to used ui in my threads, since threads class does not inherit ui.
    what should i do

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I do not understand your question, so I will just post the general rule in Qt: do not modify or create Ui elements from a thread. Qt does not support that and it can and will fail in many ways.

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andreyc
        wrote on last edited by
        #3

        In addition to sierdzio here is "an explanation":http://qt-project.org/doc/qt-5/threads-qobject.html why you should not access UI elements directly from a non-GUI thread.

        To do modifications you can emit a signal from a thread and react on the signal in UI thread.
        Take a look on "QThread description":http://qt-project.org/doc/qt-5/qthread.html#details

        1 Reply Last reply
        0
        • H Offline
          H Offline
          houmingc
          wrote on last edited by
          #4

          If so, how do i call a dialog boxes from the thread?
          my thread is used to prompt user information dialog boxes when it receives signals from another terminal
          By using signals and slots? please post an example.

          since, the background is prompting user information dialog boxes, i need the dialog boxes to disappear like 5 second later, since it is only for information, it should not require user input. I require the dialog boxes to blink or the working to blink/ showing different color to attract attendant attention.

          Can someone post an example pls?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            houmingc
            wrote on last edited by
            #5

            The link is very good.
            But how to show a user informative dialog boxes that disappear/invisible after 5 sec.

            After i compile and put my target into imx6, i saw my dialog boxes. when i touched the panel, it is like erasing the dialog boxes. Exposing background GUI. Why?

            do i need tslib for touchscreen? and what is the solution?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              s.frings74
              wrote on last edited by
              #6

              You cannot access GUI elements directly from other threads. You have to send signals to the main thread. For example, the class for your main window my provide slots like these:

              @
              public slots:
              void showMessage(QString msg);
              void enableStartButton();
              void disableStartButton();
              @

              The other threads can send signals. You connect the signals to these slots. When the other thread wants to display a message on screen, then it emits the signal that is connected to the showMessage() slot passing over the text as argument.

              So the background threads send a signal to the main thread saying "please display that message for me". And the main thread displays the message.

              If you think about a yes/no dialog box, then the main thread can send the selection (yes or no) back to the background thread again via signals.

              Be aware that you cannot pass GUI objects between threads, only simple objects like QString, QByteArray or more complicated self-created objects that dont contain GUI elements.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                s.frings74
                wrote on last edited by
                #7

                bq. But how to show a user informative dialog boxes that disappear/invisible after 5 sec.

                create a pair of signal/slot that take the message text and time as arguments:

                @
                public slots:
                void displayMessage(QString message, int seconds);
                @

                The main class then displays the message and starts a timer that removes the message after the time elapses.

                Or you send one signal to display the text and later another signal to hide the text.

                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