3 Коміти 0539ef7780 ... f6bb24adce

Автор SHA1 Опис Дата
  chenyj f6bb24adce 补充上传QT中配使用的UI文件 10 місяців тому
  chenyj e5aec9c93d Merge branch 'master' of https://gowone.dy.takin.cc/liyuezong/SmartPDCode 10 місяців тому
  chenyj a3c1166455 补充上传qt异步刷新 10 місяців тому
4 змінених файлів з 171 додано та 17 видалено
  1. 1 1
      Qt/Qt_Test/dataupdatethread.cpp
  2. 120 0
      Qt/Qt_Test/msgwidget-485.ui
  3. 46 15
      Qt/Qt_Test/widget.cpp
  4. 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)

+ 120 - 0
Qt/Qt_Test/msgwidget-485.ui

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MSGWidget</class>
+ <widget class="QWidget" name="MSGWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>144</width>
+    <height>71</height>
+   </rect>
+  </property>
+  <property name="maximumSize">
+   <size>
+    <width>16777215</width>
+    <height>16777215</height>
+   </size>
+  </property>
+  <property name="windowTitle">
+   <string/>
+  </property>
+  <property name="styleSheet">
+   <string notr="true">QWidget
+{
+	background-color: rgb(125, 125, 125);
+}
+QLabel
+{
+	color: rgb(255, 255, 255);
+}</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <property name="spacing">
+    <number>0</number>
+   </property>
+   <property name="leftMargin">
+    <number>2</number>
+   </property>
+   <property name="topMargin">
+    <number>2</number>
+   </property>
+   <property name="rightMargin">
+    <number>2</number>
+   </property>
+   <property name="bottomMargin">
+    <number>2</number>
+   </property>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <widget class="QLabel" name="label_Warning">
+     <property name="font">
+      <font>
+       <pointsize>15</pointsize>
+      </font>
+     </property>
+     <property name="styleSheet">
+      <string notr="true"/>
+     </property>
+     <property name="text">
+      <string>WARNING</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QLabel" name="label_Data">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="font">
+      <font>
+       <pointsize>12</pointsize>
+      </font>
+     </property>
+     <property name="text">
+      <string>xxxxx</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+     <property name="wordWrap">
+      <bool>true</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <spacer name="verticalSpacer_2">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

+ 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: