Microseconds Delay
-
Hi all,
Given below is my code, with delay() function i have used which takes only ms. i want to give microseconds delay in my loop function.
I tried with QThread::usleep(100) // for 100us delay. It was holding the gui to take control. i am plotting chart.
Is there any best method other than QThread to use?
delay(1000); int iCnt = 0; while(1) { delay(1); // i want to use Microseconds delay here if(iCnt < (iTmrIntvl * 2000)) { if(!dstkXVals.isEmpty()) { chrt1->m_yXVal = dstkXVals.pop(); chrt1->m_series[0]->append(iCnt, chrt1->m_yXVal); qDebug() << QString::number(iCnt) << " XVal: " << chrt1->m_yXVal; ++iCnt; } } else { if(DAcqThread::bDAQCmptd) { if(iCnt == (iTmrIntvl * 2000)) { break; } } } }
Please help. Thanks in advance
-
Hi all,
Given below is my code, with delay() function i have used which takes only ms. i want to give microseconds delay in my loop function.
I tried with QThread::usleep(100) // for 100us delay. It was holding the gui to take control. i am plotting chart.
Is there any best method other than QThread to use?
delay(1000); int iCnt = 0; while(1) { delay(1); // i want to use Microseconds delay here if(iCnt < (iTmrIntvl * 2000)) { if(!dstkXVals.isEmpty()) { chrt1->m_yXVal = dstkXVals.pop(); chrt1->m_series[0]->append(iCnt, chrt1->m_yXVal); qDebug() << QString::number(iCnt) << " XVal: " << chrt1->m_yXVal; ++iCnt; } } else { if(DAcqThread::bDAQCmptd) { if(iCnt == (iTmrIntvl * 2000)) { break; } } } }
Please help. Thanks in advance
-
Hi all,
Given below is my code, with delay() function i have used which takes only ms. i want to give microseconds delay in my loop function.
I tried with QThread::usleep(100) // for 100us delay. It was holding the gui to take control. i am plotting chart.
Is there any best method other than QThread to use?
delay(1000); int iCnt = 0; while(1) { delay(1); // i want to use Microseconds delay here if(iCnt < (iTmrIntvl * 2000)) { if(!dstkXVals.isEmpty()) { chrt1->m_yXVal = dstkXVals.pop(); chrt1->m_series[0]->append(iCnt, chrt1->m_yXVal); qDebug() << QString::number(iCnt) << " XVal: " << chrt1->m_yXVal; ++iCnt; } } else { if(DAcqThread::bDAQCmptd) { if(iCnt == (iTmrIntvl * 2000)) { break; } } } }
Please help. Thanks in advance
@dan1973 You can also go with Qt Concurrent Functionality.
-
Hi all,
Given below is my code, with delay() function i have used which takes only ms. i want to give microseconds delay in my loop function.
I tried with QThread::usleep(100) // for 100us delay. It was holding the gui to take control. i am plotting chart.
Is there any best method other than QThread to use?
delay(1000); int iCnt = 0; while(1) { delay(1); // i want to use Microseconds delay here if(iCnt < (iTmrIntvl * 2000)) { if(!dstkXVals.isEmpty()) { chrt1->m_yXVal = dstkXVals.pop(); chrt1->m_series[0]->append(iCnt, chrt1->m_yXVal); qDebug() << QString::number(iCnt) << " XVal: " << chrt1->m_yXVal; ++iCnt; } } else { if(DAcqThread::bDAQCmptd) { if(iCnt == (iTmrIntvl * 2000)) { break; } } } }
Please help. Thanks in advance
@dan1973 said in Microseconds Delay:
Is there any best method other than QThread to use?
Use a QTimer. On timeout() you can then run just a single iteration of your loop.
iCnt
would then become a member variable. In between timeouts the GUI can still run. However, this also means that you will sometimes get larger delays than specified. If the delay should never become too long you need to go with separate thread (also possible with QtConcurrent::run as mentioned before). -
Given that screens refresh with 50 or 100 Hertz, microsecond update rates are useless.
I'd use a QTimer with an resolutio of 10 milliseconds, for example. Then draw a bunch of points at once. That should give the best performance.
Regards