main.cpp 2.5 KB

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