-
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 . -
What doesn't work, what have you tried?
-
This post is deleted!
-
@kshegunov 
showing error -
Nope, there's no image.
-
-
I think the compiler's message is pretty self explanatory. Look here (Concurrent Processing section) for an example of how
piThreadCreate
is used. -
@kshegunov can u have any demo code for piThreadCreate so please share with me
-
I don't have any code. Read the linked post from my previous answer, there's the example code you're looking for.
-
I'll throw my 2cents here:
Why don't you usestd::thread
/std::async
or Qt's threading framework ? -
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]
-
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.
-
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
-
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.
-
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. -
@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.
-
how to use this predefault function of wiring pi for serial data transfer can any one have an example code for that
-
@qt_ankit_developer Did you check http://wiringpi.com/examples/ ?
You're asking how to use Wiring Pi in a Qt forum.