main.cpp 2.4 KB

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