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.7k 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #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
    • qt_ankit_developerQ Offline
      qt_ankit_developerQ Offline
      qt_ankit_developer
      wrote on last edited by kshegunov
      #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 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
        • qt_ankit_developerQ Offline
          qt_ankit_developerQ Offline
          qt_ankit_developer
          wrote on 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

          kshegunovK 1 Reply Last reply
          0
          • qt_ankit_developerQ qt_ankit_developer

            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

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on 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 last edited by
              #15

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

              1 Reply Last reply
              0
              • qt_ankit_developerQ Offline
                qt_ankit_developerQ Offline
                qt_ankit_developer
                wrote on 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
                0
                • qt_ankit_developerQ qt_ankit_developer

                  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 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
                  • qt_ankit_developerQ Offline
                    qt_ankit_developerQ Offline
                    qt_ankit_developer
                    wrote on 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
                    0
                    • qt_ankit_developerQ qt_ankit_developer

                      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 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