QT Windows GUI main window freezes while running
-
@Ravi0101 said in QT Windows GUI main window freezes while running:
pos+=arr.size();
If for some reason arr.size() starts to return 0 you will not leave the loop.
Did you analyse your app? For example running through debugger and see where it hangs? Or at least add some debug output to see what happens. -
Hi @jsulm Thank you very much for your response.
I debugged the while loop and it showed me this:
-
@jsulm I got this exception:
Exception at 0x770eb5b2, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) (first chance) in dwrite!DWriteCreateFactory
-
@Ravi0101
If you get an exception in the debugger look at the stack trace window for where it emanated from in your code. -
@JonB Also I have noticed that cpu usage is going to 100 % when running mainwindow.ui and then it freezes. could this be issue with the while loop in my code please?
@Ravi0101 said in QT Windows GUI main window freezes while running:
could this be issue with the while loop in my code please?
Yes, it can. That is why I also suggested to add some debug output.
Please add a qDebug() output just after the loop and see whether you ever see it. If you don't then you have an endless loop. -
@Ravi0101 said in QT Windows GUI main window freezes while running:
could this be issue with the while loop in my code please?
Yes, it can. That is why I also suggested to add some debug output.
Please add a qDebug() output just after the loop and see whether you ever see it. If you don't then you have an endless loop. -
@jsulm Thank you, I did that and qdebug output is displayed, please find below screenshot.
-
@Ravi0101 It's not clear from the screen shot whether the output is inside the loop or outside?
You should post code as text not pictures.@jsulm please find below.
void MainWindow::plotData(QByteArray data)
{
auto count = data.size();
qDebug() << "bytearray size 1: " << count;
data.remove(0,1);
count = data.size();
qDebug() << "bytearray size 2: " << count;qDebug() << data; qDebug() << data.size(); int pos = 0, arrsize = data.size(), sizeInArray = 3; QList<QByteArray> arrays;
std::vector<uint32_t> hrm;
// std::vector<double> hrm_final;
// uint32_t old_hrm = 0;
while(pos<arrsize){
QByteArray arr = data.mid(pos, sizeInArray);
qDebug() << arr;
uint32_t hrm = (arr[0] << 16) | (arr[1] << 8) | (arr[2]);
qDebug() << QString::number(hrm);
// if(arrsize!=0){
pos+=arr.size();//plot with hrm diffference
// if(pos == 0)
// {
// old_hrm = hrm;
// continue;
// }
//else
// {
this->plotData_Y.removeFirst();//**plot with python code reference** //double hrm_final =(hrm / qPow(2,31)) * 10; //this->plotData_Y.append(hrm_final); // qDebug() << QString::number(hrm_final); //**plot with hrm difference** // this->plotData_Y.append(old_hrm-hrm); // qDebug() << QString::number(old_hrm-hrm); //**plot with original hrm** this->plotData_Y.append(hrm); ui->plot->graph(0)->setData(this->plotData_X, this->plotData_Y); // set axes ranges, so we see all data: ui->plot->replot(); } qDebug() << "not an endless loop"; }
//}
-
@jsulm please find below.
void MainWindow::plotData(QByteArray data)
{
auto count = data.size();
qDebug() << "bytearray size 1: " << count;
data.remove(0,1);
count = data.size();
qDebug() << "bytearray size 2: " << count;qDebug() << data; qDebug() << data.size(); int pos = 0, arrsize = data.size(), sizeInArray = 3; QList<QByteArray> arrays;
std::vector<uint32_t> hrm;
// std::vector<double> hrm_final;
// uint32_t old_hrm = 0;
while(pos<arrsize){
QByteArray arr = data.mid(pos, sizeInArray);
qDebug() << arr;
uint32_t hrm = (arr[0] << 16) | (arr[1] << 8) | (arr[2]);
qDebug() << QString::number(hrm);
// if(arrsize!=0){
pos+=arr.size();//plot with hrm diffference
// if(pos == 0)
// {
// old_hrm = hrm;
// continue;
// }
//else
// {
this->plotData_Y.removeFirst();//**plot with python code reference** //double hrm_final =(hrm / qPow(2,31)) * 10; //this->plotData_Y.append(hrm_final); // qDebug() << QString::number(hrm_final); //**plot with hrm difference** // this->plotData_Y.append(old_hrm-hrm); // qDebug() << QString::number(old_hrm-hrm); //**plot with original hrm** this->plotData_Y.append(hrm); ui->plot->graph(0)->setData(this->plotData_X, this->plotData_Y); // set axes ranges, so we see all data: ui->plot->replot(); } qDebug() << "not an endless loop"; }
//}