Home > Mobile >  Under the condition of using multithreading UI refresh caton
Under the condition of using multithreading UI refresh caton

Time:09-17

It is a monitoring program, via a serial port receives 100 data processed per second (100 hz), in order to avoid the card, I will be a serial port receives in a child thread 1, serial port receiving thread 1 to receive data from the acquisition equipment, through the signal is sent to the data processing thread 2, at the same time sent to the UI graph do dynamic update, data processing thread receives 100 data points and pressure into a QVector, processing results, the results on the signal to the UI refresh tableview and bar chart, at the same time to save the results sent to the database thread 3 to save,

Problem now is that QT on interface of the operation can only be done in the main thread, related important complex operation I put into the related child thread, but because of the large amount of data, often may want to do after the (1000 hz), main interface in operation after a period of time curves of dynamic update gets stuck, let tableview to update the graph to move, bosses have what good method can solve the home screen needs to frequently updated and smooth way? Or my graph, bar chart, tableview update right way? Please instruct, graduation design is going to pay!

This is program screenshots


This graph is updated code
//update the data function, delete the first element, the tail to add new element 
Void STRESS: : lineChartUpdate1P (qreal data)
{
The switch (refreshMode)
{
Continuous refresh case 0://
Static int num=0;

If (refreshFlag==true)
{
MySeries - & gt; The clear ();
RefreshFlag=false;
}

If (mySeries - & gt; The count () & lt; XMax)//x scope, enough to add some
{
MySeries - & gt; Append (num, data);
Num++;
}
The else
{
MySeries - & gt; Remove (0);//remove the first element
MySeries - & gt; Append (0, data);//tail adding new elements (0, data) are free of 0, because here to rearrange the x coordinate

//update the point x coordinate
for(int i=0; I{
MySeries - & gt; The replace (I, I, mySeries - & gt; At (I), y ());
}
}
break;

Case 1:
If (refreshFlag==true)
{
MySeries - & gt; The clear ();
RefreshFlag=false;
}

Static int num2=0;
If (num2 & lt;=xMax)
{
MySeries - & gt; Append (num2, data);
Num2 + +;
}
Else if (num2==xMax + 1)
{
MySeries - & gt; The clear ();
Num2=0;
}
The else {}

break;

Default:
break;

}
}


This is a bar chart updated code:
 
Void STRESS: : updateBarChart (QVector * AMP)
{
QApplication: : processEvents ();

MyBarChart - & gt; RemoveAllSeries ();//delete all sequence
MyBarChart - & gt; RemoveAxis (myBarChart - & gt; AxisX ());//remove X
MyBarChart - & gt; RemoveAxis (myBarChart - & gt; AxisY ());//delete Y

QBarSet * setAmp=new QBarSet (" AMP ");//
The QStringList barCateGories;

for(int i=0; I{
SetAmp - & gt; Append (AMP - & gt; At (I));//add data
BarCateGories}

QBarSeries * series=new QBarSeries ();
The series - & gt; Append (setAmp);

QBarCategoryAxis * X=new QBarCategoryAxis ();
X-ray & gt; Append (barCateGories);

MyBarChart - & gt; SetAxisX (X, series);
MyBarChart - & gt; AddSeries (series);
}


This is the updated tableview code:
 
Void STRESS: : updateTable (QVector * AMP, QVector * AVG, QVector * ultraStress QVector * Modified QVector * Damage)
{
If (theModel - & gt; RowCount () & lt; AMP - & gt; The count ())
{
TheModel - & gt; SetRowCount (AMP - & gt; The count ());//set the number of columns equal to the amplitude point number
}

for(int i=0; I{
AItem=new QStandardItem (QString: : number (AMP - & gt; At (I)));
AItem - & gt; SetTextAlignment (Qt: : AlignHCenter);
AItem - & gt; SetForeground (QBrush (QColor (83194 ')));
AItem - & gt; The setFont (QFont (" Microsoft YaHei ", 10, QFont: : Black));
TheModel - & gt; SetItem (I, 0, aItem);//set the amplitude

AItem=new QStandardItem (QString: : number (AVG - & gt; At (I)));
AItem - & gt; SetTextAlignment (Qt: : AlignHCenter);
AItem - & gt; SetForeground (QBrush (QColor (83194 ')));
AItem - & gt; The setFont (QFont (" Microsoft YaHei ", 10, QFont: : Black));
TheModel - & gt; SetItem (I, 1, aItem);//set the mean

AItem=new QStandardItem (QString: : number (ultraStress - & gt; At (I)));
AItem - & gt; SetTextAlignment (Qt: : AlignHCenter);
AItem - & gt; SetForeground (QBrush (QColor (245211111)));
AItem - & gt; The setFont (QFont (" Microsoft YaHei ", 10, QFont: : Black));
TheModel - & gt; SetItem (I, 2, aItem);//set the limit stress

AItem=new QStandardItem (QString: : number (Modified - & gt; At (I)));
AItem - & gt; SetTextAlignment (Qt: : AlignHCenter);
AItem - & gt; SetForeground (QBrush (QColor (0120215)));
AItem - & gt; The setFont (QFont (" Microsoft YaHei ", 10, QFont: : Black));
TheModel - & gt; SetItem (I, 3, aItem);//set the revised stress

AItem=new QStandardItem (QString: : number (Damage - & gt; At (I)));
AItem - & gt; SetTextAlignment (Qt: : AlignHCenter);
AItem - & gt; SetForeground (QBrush (QColor (0, 255)));
AItem - & gt; The setFont (QFont (" Microsoft YaHei ", 10, QFont: : Black));
TheModel - & gt; SetItem (I, 4, aItem);//set any
}
}


Bosses to help me see see!

CodePudding user response:

If waiting for tableview refresh because graph, then is the tableview processing efficiency is not high, I see you in the refresh function has been the creation of the variables, these variables itself load is bigger, you can look at this to optimization, reduce the number of objects to create, if still won't do, I suggest not to use the tableview, because you just want to show it with a form to display the data, tableview actually also carry a lot of you don't need to operate, it is because the low efficiency of these actions lead to your form, you can draw out a form, it can greatly improve performance, also don't know you is how to draw curve, curve drawing didn't handle, cause caton

CodePudding user response:

PaintEvent perform too much stuff inside
  •  Tags:  
  • Qt
  • Related