Home > other >  Qprocess and Qthread used jointly with jam
Qprocess and Qthread used jointly with jam

Time:01-24

I want to realize the function of collect data from serial port, and the judging and handling, if the data (such as temperature) is greater than a certain range, the alarm prompt, including data acquisition and alarm defines two threads, data processing and display is the main thread, thread data acquisition function is to collect data, collecting a package after launching a signal, notice the main thread processing, according to the judgment and the main thread to start the alarm thread at the same time, if the collection value is too large, the police (use madplay, use AV97 play music), signal code following the main function: RecvThread * m_recvthread; Int main (int arg c, char * argv []) {QApplication app (arg c, argv); Papp=& amp; The app; M_recvthread=new RecvThread ();//data acquisition thread (serial port receiving) m_recvthread - & gt; Start (). FunctionList DLG.//main interface DLG. The show (); Return the app. The exec (); } functionlist. CPP RecvThread: : RecvThread () {fd=1; {} void RecvThread: : run () comm ();//open the serial port while (true) {read (fd, comm_str, 25); If (comm_str [24]==126) emit sendData publishes the event ();//end of the packet transmitting}} FunctionList: : FunctionList () {connect (m_recvthread, SIGNAL (sendData publishes the event ()), and this, SLOT (receiveData ())); Signal void tank} FunctionList: : receiveData () {AlarmThread * thread=new AlarmThread ();//define temperature alarm thread=(comm_str1 [11]);//thread - needed data & gt; Start ().//alarm thread starts} AlarmThread: : AlarmThread {} ()//alarm thread void AlarmThread: : run () {QProcess proc. With the method of QProcess, call an external application madplay vocal music QString program="/Qtopia/demo/bin/madplay"; The QStringList filename1; Filename1 & lt; & lt;"/MNT/yaffs/1. Mp3 "; If (temperature> 20) proc. Start (program, filename1); Proc. WaitForFinished (); } the question now is, I continued to launch a serial port said high temperature data, beginning around seven to eight times, can be alarm, normal play music, but continue to send after high temperature data, the whole program died, when the machine, don't know why? Oneself think there may be two possible: 1: the alarm thread problem, alarm thread no like data receiving threads in the main function, but in the main thread slot function, lead to, every time a serial port receives the data start slot function will start this thread at a time, lead to multiple threads to start at the same time, 2: the problem of qprocess, each invocation, qprocess is not the end, the multiple proc in running at the same time, running out of resources development board, but still not solved, which can help to think about, but a problem for a long time,

CodePudding user response:

Code like this, who show you just strange
  • Related