Sfoglia il codice sorgente

补充上传qt异步刷新

chenyj 10 mesi fa
parent
commit
a3c1166455
3 ha cambiato i file con 51 aggiunte e 17 eliminazioni
  1. 1 1
      Qt/Qt_Test/dataupdatethread.cpp
  2. 46 15
      Qt/Qt_Test/widget.cpp
  3. 4 1
      Qt/Qt_Test/widget.h

+ 1 - 1
Qt/Qt_Test/dataupdatethread.cpp

@@ -361,7 +361,7 @@ void DataUpdateThread::ReadMSG()
                         break;
                     }else
                     {
-                        //qDebug()<<nIndexMSG<<"="<<m_shmData->nTypeCtrlType[nIndexMSG];
+                        qDebug()<<nIndexMSG<<"="<<m_shmData->nTypeCtrlType[nIndexMSG];
                     }
                 }
                 if(isHaveMSG)

+ 46 - 15
Qt/Qt_Test/widget.cpp

@@ -47,6 +47,15 @@ Widget::Widget(QWidget *parent) :
     //ui->stackedWidget_Main->setCurrentWidget(ui->page_7);
     m_pMSGWidget=new MSGWidget(this);
     m_pMSGWidget->hide();
+    bool bDataSet=connect(this,SIGNAL(signal_SetData(QLabel*,QString)),this,SLOT(SetData(QLabel*,QString)),Qt::QueuedConnection);
+    if(bDataSet)
+    {
+        qDebug()<<"Connect Link Success";
+    }else
+    {
+        qDebug()<<"Connect Link Error";
+    }
+
 }
 
 Widget::~Widget()
@@ -140,37 +149,51 @@ void Widget::SetData(QLabel *pLab, QString strShow)
 {
     if(pLab)
     {
+        if(pLab==ui->label_V)
+        {
+            if(ui->label_V->text()!=strShow)
+            {
+                if(strShow=="OFF")
+                {
+                    ui->label_V->setStyleSheet(LABEL_RED);
+                }else
+                {
+                    ui->label_V->setStyleSheet("QLabel{color: rgb(0, 255, 0);}");
+                }
+            }
+        }
         pLab->setText(strShow);
     }
+
 }
 
 void Widget::SetV(QString strShow)
 {
-    SetData(ui->label_8,strShow);SetData(ui->label_phV,strShow);
+    emit signal_SetData(ui->label_8,strShow);emit signal_SetData(ui->label_phV,strShow);
     if(m_nMonwayType==3)
     {
-       SetData(ui->label_V,strShow);
+       emit signal_SetData(ui->label_V,strShow);
     }
 }
 
-void Widget::SetA(QString strShow){SetData(ui->label_13,strShow);SetData(ui->label_A,strShow);SetData(ui->label_phA,strShow);}
+void Widget::SetA(QString strShow){emit signal_SetData(ui->label_13,strShow);emit signal_SetData(ui->label_A,strShow);emit signal_SetData(ui->label_phA,strShow);}
 
-void Widget::SetW(QString strShow){SetData(ui->label_16,strShow);SetData(ui->label_W,strShow);SetData(ui->label_phW,strShow);}
+void Widget::SetW(QString strShow){emit signal_SetData(ui->label_16,strShow);emit signal_SetData(ui->label_W,strShow);emit signal_SetData(ui->label_phW,strShow);}
 
-void Widget::SetF(QString strShow){SetData(ui->label_15,strShow);SetData(ui->label_F,strShow);SetData(ui->label_phF,strShow);}
+void Widget::SetF(QString strShow){emit signal_SetData(ui->label_15,strShow);emit signal_SetData(ui->label_F,strShow);emit signal_SetData(ui->label_phF,strShow);}
 
-void Widget::SetSUM(QString strShow){SetData(ui->label_14,strShow);SetData(ui->label_S,strShow);SetData(ui->label_phKw,strShow);}
+void Widget::SetSUM(QString strShow){emit signal_SetData(ui->label_14,strShow);emit signal_SetData(ui->label_S,strShow);emit signal_SetData(ui->label_phKw,strShow);}
 
-void Widget::SetT(QString strShow){SetData(ui->label_Temp,strShow+ " ℃");}
-void Widget::SetH(QString strShow){SetData(ui->label_Humidity,strShow+" %");}
-void Widget::SetCO2(QString strShow){SetData(ui->label_CO2,strShow+" PPM");}
+void Widget::SetT(QString strShow){emit signal_SetData(ui->label_Temp,strShow+ " ℃");}
+void Widget::SetH(QString strShow){emit signal_SetData(ui->label_Humidity,strShow+" %");}
+void Widget::SetCO2(QString strShow){emit signal_SetData(ui->label_CO2,strShow+" PPM");}
 
-void Widget::SetVer(QString strShow){SetData(ui->label_2,"Version:"+strShow);}
+void Widget::SetVer(QString strShow){emit signal_SetData(ui->label_2,"Version:"+strShow);}
 
 void Widget::SetStatus(QString strShow){
     if(m_nMonwayType==2)
     {
-       SetData(ui->label_V,strShow);
+        emit signal_SetData(ui->label_V,strShow);
     }
 
 }
@@ -186,7 +209,7 @@ void Widget::SetIP(QString strIP)
 void Widget::setCH(int nIndex)
 {
     QString  strShow=QString("Output CH%1").arg(nIndex);
-    SetData(ui->label_chName,strShow);
+    emit signal_SetData(ui->label_chName,strShow);
 
 }
 void Widget::setPH(int nIndex,int nPHType)
@@ -214,7 +237,7 @@ void Widget::setPH(int nIndex,int nPHType)
     {
         strPHShow=QString("Output CH%1%2").arg(nIndex).arg(strShow);
     }
-    SetData(ui->label_18,strPHShow);
+    emit signal_SetData(ui->label_18,strPHShow);
     qDebug()<<"CH_Select:"<<nIndex<<"PH_Select:"<<nPHType;
 }
 /*
@@ -305,7 +328,11 @@ void Widget::pageUp()
     }
         break;
     }
+    int nMainIndex= ui->stackedWidget_Main->currentIndex();
+    int nbaseIndex= ui->stackedWidget->currentIndex();
+    int nSetingIndex= ui->stackedWidget_Setting->currentIndex();
     qDebug()<<"Index:"<<nIndex<<"ChID:"<<nChidIndex;
+    qDebug()<<"QTStackedIndex Base="<<nbaseIndex<<" Main="<<nMainIndex<<" Set="<<nSetingIndex;
 }
 
 void Widget::pageDown()
@@ -356,6 +383,10 @@ void Widget::pageDown()
         ui->stackedWidget_Main->setCurrentIndex(nIndex-1);
     }
     qDebug()<<"Index:"<<nIndex<<"ChID:"<<nChidIndex;
+    int nMainIndex= ui->stackedWidget_Main->currentIndex();
+    int nbaseIndex= ui->stackedWidget->currentIndex();
+    int nSetingIndex= ui->stackedWidget_Setting->currentIndex();
+    qDebug()<<"QTStackedIndex Base="<<nbaseIndex<<" Main="<<nMainIndex<<" Set="<<nSetingIndex;
 }
 
 void Widget::ChangeView(int widgetType, int nIndex)
@@ -554,13 +585,13 @@ void Widget::setMonwayType(int nType)
     {
         ui->label_34->setText("Volt(V):");
         ui->label_V->setStyleSheet("");
-        SetData(ui->label_V,"0.00");
+        emit signal_SetData(ui->label_V,"0.00");
     }
         break;
     default:
     {
         ui->label_34->setText("Switch");
-        SetData(ui->label_V,"OFF");
+        emit signal_SetData(ui->label_V,"OFF");
 #ifdef RS485Type
         ui->label_V->setStyleSheet("QLabel {color: rgb(0,255,255);}");
 #else

+ 4 - 1
Qt/Qt_Test/widget.h

@@ -49,7 +49,7 @@ public:
     QString ReadIP();
 
 
-    void SetData(QLabel* pLab,QString strShow);
+
     void SetV(QString strShow);
     void SetA(QString strShow);
     void SetW(QString strShow);
@@ -98,7 +98,10 @@ protected:
 signals:
     void signal_ClickMSG();//报警确认
 
+    void signal_SetData(QLabel* pLab,QString strShow);
 public slots:
+    //改为异步刷新数据
+    void SetData(QLabel* pLab,QString strShow);
     //显示msg窗口
     void ShowMSGWidget(QString strShowData);
 public: