Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. pThreadCreate with main gui thread
Forum Updated to NodeBB v4.3 + New Features

pThreadCreate with main gui thread

Scheduled Pinned Locked Moved Unsolved C++ Gurus
19 Posts 5 Posters 6.6k 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.
  • Q Offline
    Q Offline
    qt_ankit_developer
    wrote on 30 Aug 2017, 06:42 last edited by
    #1

    i am facing problem with pThreadCreate. not able to start possix thread with main gui i want to run possix thread with serial .
    please suggest me how to use pThreadCreate with serial data .

    K 1 Reply Last reply 30 Aug 2017, 08:19
    0
    • Q qt_ankit_developer
      30 Aug 2017, 06:42

      i am facing problem with pThreadCreate. not able to start possix thread with main gui i want to run possix thread with serial .
      please suggest me how to use pThreadCreate with serial data .

      K Offline
      K Offline
      kshegunov
      Moderators
      wrote on 30 Aug 2017, 08:19 last edited by
      #2

      What doesn't work, what have you tried?

      Read and abide by the Qt Code of Conduct

      Q 1 Reply Last reply 1 Sept 2017, 08:39
      1
      • Q Offline
        Q Offline
        qt_ankit_developer
        wrote on 1 Sept 2017, 08:33 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • K kshegunov
          30 Aug 2017, 08:19

          What doesn't work, what have you tried?

          Q Offline
          Q Offline
          qt_ankit_developer
          wrote on 1 Sept 2017, 08:39 last edited by
          #4

          @kshegunov ![0_1504255005771_IMG_20170901_125055.jpg](Uploading 100%)
          showing error

          K 1 Reply Last reply 1 Sept 2017, 09:24
          0
          • Q qt_ankit_developer
            1 Sept 2017, 08:39

            @kshegunov ![0_1504255005771_IMG_20170901_125055.jpg](Uploading 100%)
            showing error

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 1 Sept 2017, 09:24 last edited by
            #5

            Nope, there's no image.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qt_ankit_developer
              wrote on 2 Sept 2017, 05:36 last edited by
              #6

              alt text
              alt text

              K 1 Reply Last reply 2 Sept 2017, 11:00
              0
              • Q qt_ankit_developer
                2 Sept 2017, 05:36

                alt text
                alt text

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 2 Sept 2017, 11:00 last edited by
                #7

                I think the compiler's message is pretty self explanatory. Look here (Concurrent Processing section) for an example of how piThreadCreate is used.

                Read and abide by the Qt Code of Conduct

                Q 1 Reply Last reply 4 Sept 2017, 10:34
                1
                • K kshegunov
                  2 Sept 2017, 11:00

                  I think the compiler's message is pretty self explanatory. Look here (Concurrent Processing section) for an example of how piThreadCreate is used.

                  Q Offline
                  Q Offline
                  qt_ankit_developer
                  wrote on 4 Sept 2017, 10:34 last edited by
                  #8

                  @kshegunov can u have any demo code for piThreadCreate so please share with me

                  K 1 Reply Last reply 4 Sept 2017, 13:27
                  0
                  • Q qt_ankit_developer
                    4 Sept 2017, 10:34

                    @kshegunov can u have any demo code for piThreadCreate so please share with me

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 4 Sept 2017, 13:27 last edited by
                    #9

                    I don't have any code. Read the linked post from my previous answer, there's the example code you're looking for.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0
                    • V Offline
                      V Offline
                      VRonin
                      wrote on 4 Sept 2017, 15:03 last edited by VRonin 9 Apr 2017, 15:04
                      #10

                      I'll throw my 2cents here:
                      Why don't you use std::thread/std::async or Qt's threading framework ?

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      1 Reply Last reply
                      2
                      • Q Offline
                        Q Offline
                        qt_ankit_developer
                        wrote on 7 Sept 2017, 07:17 last edited by kshegunov 9 Aug 2017, 00:26
                        #11

                        this is the code--

                        #include<wiringpi.h>
                        #define _PI_THREAD(name)
                         
                        void MainWindow::onclicked()//this is a button slot
                        {
                        piThreadCreate(name);//creating thread name
                        }
                        PI_THREAD(name)//predefault function of wiring pi thread concurrent 
                        {
                        ui->label->settext("show");
                        }
                        

                        but the problem is that on compiling it show a error that ui is not declared in the scope.
                        so how to declare

                        [Added code tags ~kshegunov]

                        1 Reply Last reply
                        0
                        • BjornWB Offline
                          BjornWB Offline
                          BjornW
                          wrote on 7 Sept 2017, 08:13 last edited by
                          #12

                          What is PI_THREAD(name)? What does it expand to? It is certainly not a member function of your MainWindow and thus it cannot access the ui object.

                          Suggestion: Don't use some very low level library (wiringpi) to set gui level text. It is not a good idea! What are you trying to do, really? Use QThread and connect any object residing there by signal/slots to your gui thread, if you want to run your code in a separare thread.

                          1 Reply Last reply
                          1
                          • Q Offline
                            Q Offline
                            qt_ankit_developer
                            wrote on 7 Sept 2017, 09:15 last edited by
                            #13

                            i use the wiring pi concurrent process which was give in wiring pi library because in secondary(p thread) thread i want to continuously check for serial data which was from raspberry pins GPIO serial pins.

                            according to my knowledge we cant access the gpio from a normal QTHREAD

                            Give me some approach how to create a secondary thread which continuously check for serial data at the same time gui is also running what type of thread i have to use to make serial checking as a secondary thread while running gui as primary

                            K 1 Reply Last reply 8 Sept 2017, 00:27
                            0
                            • Q qt_ankit_developer
                              7 Sept 2017, 09:15

                              i use the wiring pi concurrent process which was give in wiring pi library because in secondary(p thread) thread i want to continuously check for serial data which was from raspberry pins GPIO serial pins.

                              according to my knowledge we cant access the gpio from a normal QTHREAD

                              Give me some approach how to create a secondary thread which continuously check for serial data at the same time gui is also running what type of thread i have to use to make serial checking as a secondary thread while running gui as primary

                              K Offline
                              K Offline
                              kshegunov
                              Moderators
                              wrote on 8 Sept 2017, 00:27 last edited by
                              #14

                              You most probably forgot the headers, so that's why you get the compiler error. However it's more concerning the way you access the GUI from a separate thread, which is not safe whatever threading technology you choose.

                              Read and abide by the Qt Code of Conduct

                              1 Reply Last reply
                              3
                              • BjornWB Offline
                                BjornWB Offline
                                BjornW
                                wrote on 8 Sept 2017, 06:43 last edited by
                                #15

                                Can't you just use a QThread or std::thread? Do you need this pThread?

                                1 Reply Last reply
                                0
                                • Q Offline
                                  Q Offline
                                  qt_ankit_developer
                                  wrote on 18 Sept 2017, 12:20 last edited by
                                  #16

                                  hello,
                                  i am explaining what i want to do .i am using Qt 5.9 i have created GUI application window which is run perfectly. In this i am using serial library of Wiring pi library "wiring pi.h" in Qt . I am transferring serial data in main thread.
                                  now i want to transfer serial data from gpio to secondary thread .

                                  -> so I want to create a secondary thread in qt which run concurrently with main GUI thread and continuously check for serial data when ever the secondary thread get the data then the data is transferred to main GUI thread.
                                  so what type of threading i use to continuously monitor serial data in secondary thread with out GUI blocking.

                                  jsulmJ 1 Reply Last reply 19 Sept 2017, 05:28
                                  0
                                  • Q qt_ankit_developer
                                    18 Sept 2017, 12:20

                                    hello,
                                    i am explaining what i want to do .i am using Qt 5.9 i have created GUI application window which is run perfectly. In this i am using serial library of Wiring pi library "wiring pi.h" in Qt . I am transferring serial data in main thread.
                                    now i want to transfer serial data from gpio to secondary thread .

                                    -> so I want to create a secondary thread in qt which run concurrently with main GUI thread and continuously check for serial data when ever the secondary thread get the data then the data is transferred to main GUI thread.
                                    so what type of threading i use to continuously monitor serial data in secondary thread with out GUI blocking.

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on 19 Sept 2017, 05:28 last edited by
                                    #17

                                    @qt_ankit_developer Here:

                                    PI_THREAD(name)//predefault function of wiring pi thread concurrent 
                                    {
                                    ui->label->settext("show");
                                    }
                                    

                                    you're accessing UI from a second thread. It is important to know that in Qt (and many other GUI frameworks) the UI should only be changed from main thread. You should change your implementation and just notify the main thread from second thread when needed. Main thread then changes the UI.

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    2
                                    • Q Offline
                                      Q Offline
                                      qt_ankit_developer
                                      wrote on 20 Sept 2017, 08:55 last edited by
                                      #18

                                      how to use this predefault function of wiring pi for serial data transfer can any one have an example code for that

                                      jsulmJ 1 Reply Last reply 20 Sept 2017, 09:43
                                      0
                                      • Q qt_ankit_developer
                                        20 Sept 2017, 08:55

                                        how to use this predefault function of wiring pi for serial data transfer can any one have an example code for that

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on 20 Sept 2017, 09:43 last edited by
                                        #19

                                        @qt_ankit_developer Did you check http://wiringpi.com/examples/ ?
                                        You're asking how to use Wiring Pi in a Qt forum.

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply
                                        2

                                        • Login

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