main.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "widget.h"
  2. #include <QApplication>
  3. #include "dataupdatethread.h"
  4. #include "buttonclickthread.h"
  5. #include <QScreen>
  6. #include <QGraphicsScene>
  7. #include <QGraphicsView>
  8. #include "pdu_ctrl.h"
  9. int main(int argc, char *argv[])
  10. {
  11. QApplication a(argc, argv);
  12. //窗口初始化
  13. pdu_Ctrl::instance();
  14. Widget w;
  15. qDebug()<<"widget End";
  16. QGraphicsScene *scene = new QGraphicsScene;
  17. QGraphicsView *gview = new QGraphicsView(scene);
  18. QGraphicsProxyWidget *g_proxy_widget;
  19. qDebug()<<"x:"<<w.size().width()<<"y:"<<w.size().height();
  20. QScreen *desktop = QApplication::primaryScreen();
  21. QRect screen_info = desktop->geometry();
  22. // Rotation 90 degree
  23. g_proxy_widget = scene->addWidget((QWidget*)&w);
  24. g_proxy_widget->setRotation(0);
  25. // Set window size
  26. #ifdef RS485Type
  27. w.resize(screen_info.width()+2, screen_info.height()+2);
  28. qDebug()<<"Rect:x="<<screen_info.width()<<"y="<<screen_info.height();
  29. qDebug()<<"WRect:x="<<w.width()<<"y="<<w.height();
  30. #else
  31. w.resize(screen_info.width(), screen_info.height());
  32. qDebug()<<"Rect:x="<<screen_info.width()<<"y="<<screen_info.height();
  33. #endif
  34. pdu_Ctrl::instance()->InitData(&w,g_proxy_widget,gview,screen_info.width(), screen_info.height());
  35. gview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  36. gview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  37. gview->setStyleSheet("border:none");
  38. gview->showFullScreen();
  39. qDebug()<<"x:"<<w.size().width()<<"y:"<<w.size().height();
  40. qDebug()<<"Thread start";
  41. QString appDirPath = QCoreApplication::applicationDirPath();
  42. pdu_Ctrl::instance()->strSqliteAddress=appDirPath+"/pdu_dat.db";
  43. pdu_Ctrl::instance()->ReadModbusInit();
  44. //============================线程开启====================================
  45. //数据更新线程
  46. DataUpdateThread thread_Update(nullptr);
  47. thread_Update.SetShowWidget(&w);
  48. //QString appDirPath = QCoreApplication::applicationDirPath();
  49. //thread_Update.strSqliteAddress=appDirPath+"/pdu_dat.db";
  50. thread_Update.initShm();
  51. thread_Update.start();
  52. //GPIO更新线程
  53. ButtonClickThread thread_Button(nullptr);
  54. thread_Button.InitConnect();
  55. thread_Button.start();
  56. //thread_Button.InitConnect();
  57. //w.ShowMSGWidget("Temperature and humidity sensor 湿度 超过上限");
  58. int ret=a.exec();
  59. //析构
  60. thread_Update.isRunStats=false;
  61. thread_Update.wait();
  62. thread_Button.isRunning=false;
  63. thread_Button.wait();
  64. pdu_Ctrl::distory();
  65. return ret;
  66. }