ソースを参照

增加设备开机启动,退出关机,及登录页面的信息展示, debug/release 模式区分

guoqiang 2 年 前
コミット
8537a08fb2
共有9 個のファイルを変更した173 個の追加15 個の削除を含む
  1. 1 1
      Calibrationpara.cpp
  2. 2 2
      Deviceinfo.cpp
  3. 1 1
      PageSelfTest.qml
  4. 3 0
      ValveTest.pro
  5. 2 1
      ValveTest.pro.user
  6. 40 0
      backendlogic.cpp
  7. 20 0
      backendlogic.h
  8. 51 0
      main.cpp
  9. 53 10
      main.qml

+ 1 - 1
Calibrationpara.cpp

@@ -451,7 +451,7 @@ void CalibrationPara::add_default()
     para.innerki = 80;
     para.innerkd = 60;
     para.innermaxI = 15;
-    para.innerIstep = 1;
+    para.innerIstep = 2;
     para.innerDstep = 10;
 
     m_paras.push_back(para);

+ 2 - 2
Deviceinfo.cpp

@@ -10,8 +10,8 @@
 #include <QJsonArray>
 #include <QJsonObject>
 
-#define CONFIG_PATH  "D:/Profile"
-#define CONFIG_FULL_PATH  "D:/Profile/deviceinfo.ini"
+#define CONFIG_PATH  "C:/Profile"
+#define CONFIG_FULL_PATH  "C:/Profile/deviceinfo.ini"
 #define CONFIG_NAME  "deviceinfo.ini"
 
 DeviceInfo::DeviceInfo()

+ 1 - 1
PageSelfTest.qml

@@ -242,7 +242,7 @@ Item {
         m_maxY = (m_maxY < number)? number:m_maxY
         m_minY = (m_minY > number)? number:m_minY
 
-        curveDisplay.setRange_Y(m_minY-1.0, m_maxY+1.0)
+        curveDisplay.setRange_Y(m_minY-1.0, m_maxY+2.0)
 
         if(pressureCnt <= 180){
             curveDisplay.spline.append(pressureCnt-1,number)

+ 3 - 0
ValveTest.pro

@@ -3,6 +3,7 @@ QT   += serialport
 QT += testlib
 QT += widgets
 QT += virtualkeyboard axcontainer
+#QT += core
 
 
 
@@ -20,6 +21,7 @@ SOURCES += \
         PressureSensor.cpp \
         Standard.cpp \
         TestService.cpp \
+        backendlogic.cpp \
         ballvalve.cpp \
         main.cpp \
         pid.cpp \
@@ -55,6 +57,7 @@ HEADERS += \
     PressureSensor.h \
     Standard.h \
     TestService.h \
+    backendlogic.h \
     ballvalve.h \
     pid.h \
     report.h \

+ 2 - 1
ValveTest.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 8.0.0, 2023-07-07T09:15:14. -->
+<!-- Written by QtCreator 8.0.0, 2023-07-13T11:13:33. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -246,6 +246,7 @@
     <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
+    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/Code/QTapps/build-ValveTest-Desktop_Qt_5_15_2_MinGW_32_bit-Release</value>
    </valuemap>
    <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>

+ 40 - 0
backendlogic.cpp

@@ -0,0 +1,40 @@
+#include "backendlogic.h"
+#include "Deviceinfo.h"
+#include <QProcess>
+#include <QDebug>
+#include <QJsonDocument>
+#include <QJsonArray>
+#include <QJsonObject>
+#include <windows.h>
+
+void BackendLogic::shutdown()
+{
+#if 0
+    QString program = "C:/WINDOWS/system32/shutdown.exe";
+    QStringList arguments;
+    arguments << "-s -t 00";
+    QProcess *myProcess = new QProcess();
+    myProcess->start(program, arguments);
+#else
+    #ifdef QT_NO_DEBUG
+    system("shutdown -s -t 00");
+    #endif
+    #ifdef QT_DEBUG
+       //system("shutdown -s -t 00");
+       exit(0);
+    #endif
+#endif
+}
+
+QJsonObject BackendLogic::getDeviceInfo()
+{
+    QJsonObject jsonObj;
+    DeviceInfo  devinfo;
+
+    jsonObj.insert("model", devinfo.m_model);
+    jsonObj.insert("id", devinfo.m_id);
+    jsonObj.insert("name", devinfo.m_name);
+    jsonObj.insert("manufacture", devinfo.m_manufacture);
+
+    return jsonObj;
+}

+ 20 - 0
backendlogic.h

@@ -0,0 +1,20 @@
+#ifndef BACKENDLOGIC_H
+#define BACKENDLOGIC_H
+
+#include <QObject>
+#include <QJsonObject>
+
+class BackendLogic : public QObject
+{
+ Q_OBJECT
+public:
+ explicit BackendLogic(QObject *parent = nullptr) {
+ Q_UNUSED(parent);}
+ Q_INVOKABLE int getData() {return mValue; }
+ Q_INVOKABLE void shutdown();
+ Q_INVOKABLE QJsonObject getDeviceInfo();
+private:
+ int mValue = 100;
+};
+
+#endif // BACKENDLOGIC_H

+ 51 - 0
main.cpp

@@ -3,13 +3,60 @@
 #include <QQmlContext>
 #include <QApplication>
 #include<QMessageBox>
+#include <QSettings>
 
 #include "TestService.h"
 #include "Standard.h"
 #include "Calibrationpara.h"
+#include "backendlogic.h"
 
 #include "DLog.h"
 
+#if 0
+#define AUTO_RUN_KEY	"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
+//设置/取消自启动
+//isStart: true(开机启动)    false(开机不启动)
+void ServiceMediaPlayer::setMyAppAutoRun(bool isStart)
+{
+    QString application_name = QApplication::applicationName();//获取应用名称
+    QSettings *settings = new QSettings(AUTO_RUN_KEY, QSettings::NativeFormat);//创建QSetting, 需要添加QSetting头文件
+    if(isStart)
+    {
+        QString application_path = QApplication::applicationFilePath();//找到应用的目录
+        settings->setValue(application_name, application_path.replace("/", "\\"));//写入注册表
+    }
+    else
+    {
+        settings->remove(application_name);		//从注册表中删除
+    }
+}
+
+#endif
+
+void SetProcessAutoRunSelf(const QString &appPath)
+{
+    //注册表路径需要使用双反斜杠,如果是32位系统,要使用QSettings::Registry32Format
+    QSettings settings("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
+                       QSettings::Registry64Format);
+
+    //以程序名称作为注册表中的键
+    //根据键获取对应的值(程序路径)
+    QFileInfo fInfo(appPath);
+    QString name = fInfo.baseName();
+    QString path = settings.value(name).toString();
+
+    //如果注册表中的路径和当前程序路径不一样,
+    //则表示没有设置自启动或自启动程序已经更换了路径
+    //toNativeSeparators的意思是将"/"替换为"\"
+    QString newPath = QDir::toNativeSeparators(appPath);
+    if (path != newPath)
+    {
+
+        settings.setValue(name, newPath);
+    }
+}
+
+
 QObject *standardmananger_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
 {
     Q_UNUSED(engine)
@@ -34,7 +81,10 @@ int main(int argc, char *argv[])
 #endif
     QApplication app(argc, argv);
 
+#ifdef QT_NO_DEBUG
+    SetProcessAutoRunSelf(qApp->applicationFilePath());//创建程序自启注册表
     qInstallMessageHandler(myMsgOutput);
+#endif
     DLog_Init();
 
     //QMessageBox::critical(NULL, "critical", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
@@ -44,6 +94,7 @@ int main(int argc, char *argv[])
     qmlRegisterSingletonType<StandardManager>("TService", 1, 0, "CalibrationPara",calibrationpara_provider);
 
     qmlRegisterType<TestService>("TService",1,0,"TestService");
+    qmlRegisterType<BackendLogic>("BackendLogic", 1, 0, "BackendLogic");
 
     StandardManager::instance();
 

+ 53 - 10
main.qml

@@ -7,6 +7,7 @@ import QtQuick.Controls.Styles 1.4
 import QtQuick.VirtualKeyboard 2.15
 
 import TService 1.0
+import BackendLogic 1.0
 
 Window {
     id:main_window
@@ -25,6 +26,10 @@ Window {
         source: "img/main_zjtj_bj.jpg"
     }
 
+    BackendLogic {
+            id: backend
+    }
+
     Rectangle{
         id: logo
         x: 20
@@ -78,21 +83,53 @@ Window {
         }
 
         onClicked: {
-            Qt.quit()
+
+            backend.shutdown()
+
         }
     }
 
-    Text {
-        id: ver_text
-        anchors.left: parent.left
-        anchors.bottom: parent.bottom
-        anchors.leftMargin: 30
-        anchors.bottomMargin: 70
-        text: qsTr("SoftWare Version:  V2.1.2")
-        font.bold: true
+    Rectangle{
+        id: info
+        x: 30
+        y: 650
+
+        width:500
+        height:400
+        color:"transparent"
+
+        Column{
+            spacing: 2
+            Text {
+                id: ver_text
+                text: qsTr("软件版本: V2.1.2")
+                font.bold: true
+            }
+
+            Text {
+                id: model_text
+                text: qsTr("")
+                font.bold: true
+            }
+
+            Text {
+                id: devid_text
+                text: qsTr("")
+                font.bold: true
+            }
+
+            Text {
+                id: manufacture_text
+                text: qsTr("")
+                font.bold: true
+            }
+        }
+
     }
 
 
+
+
     Item {
         id: cornerItem
         x: 0
@@ -108,7 +145,13 @@ Window {
         anchors.centerIn: parent
     }
 
-    //Component.onCompleted: myLoder.sourceComponent = firstpage
+    Component.onCompleted:{
+        var jsonobj = backend.getDeviceInfo()
+        model_text.text = "设备型号:"+jsonobj.model
+        devid_text.text = "设备ID:"+jsonobj.id
+        manufacture_text.text = "制造商:"+jsonobj.manufacture
+
+    }
 
     Component{
         id:firstpage