main.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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()<<"Widget-x:"<<w.size().width()<<"y:"<<w.size().height();
  20. qDebug()<<"get Screen Start";
  21. QScreen *desktop = QApplication::primaryScreen();
  22. QRect screen_info = desktop->geometry();
  23. qDebug()<<"get Screen End";
  24. // Rotation 90 degree
  25. g_proxy_widget = scene->addWidget((QWidget*)&w);
  26. g_proxy_widget->setRotation(0);
  27. // Set window size
  28. qDebug()<<"Reset Widget";
  29. w.resize(screen_info.width(), screen_info.height());
  30. qDebug()<<"Rect:x="<<screen_info.width()<<"y="<<screen_info.height();
  31. /*
  32. QRect screen_info(0,0,128,64);
  33. w.resize(screen_info.width(), screen_info.height());
  34. */
  35. qDebug()<<"get Screen End";
  36. qDebug()<<"Rect:x="<<screen_info.width()<<"y="<<screen_info.height();
  37. pdu_Ctrl::instance()->InitData(&w,g_proxy_widget,gview,screen_info.width(), screen_info.height());
  38. gview->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  39. gview->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  40. gview->setStyleSheet("border:none");
  41. gview->showFullScreen();
  42. qDebug()<<"x:"<<w.size().width()<<"y:"<<w.size().height();
  43. qDebug()<<"Modbus Thread start";
  44. QString appDirPath = QCoreApplication::applicationDirPath();
  45. pdu_Ctrl::instance()->strSqliteAddress=appDirPath+"/pdu_dat.db";
  46. pdu_Ctrl::instance()->ReadModbusInit();
  47. //============================线程开启====================================
  48. //数据更新线程
  49. DataUpdateThread thread_Update(nullptr);
  50. thread_Update.pwidget=&w;
  51. //QString appDirPath = QCoreApplication::applicationDirPath();
  52. //thread_Update.strSqliteAddress=appDirPath+"/pdu_dat.db";
  53. thread_Update.initShm();
  54. thread_Update.start();
  55. //GPIO更新线程
  56. qDebug()<<"GPIO Thread start";
  57. ButtonClickThread thread_Button(nullptr);
  58. thread_Button.InitConnect();
  59. thread_Button.start();
  60. //thread_Button.InitConnect();
  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. }