hi all
this is Full Source of My Program
Qt Code:
  1. #include "mainwindow.h"
  2. #include <QApplication>
  3. #include <QSystemTrayIcon>
  4. #include <QMenu>
  5. #include <QAction>
  6. #include <QFileDialog>
  7. #include <QMessageBox>
  8. #include <thread>
  9. #include <fstream>
  10. #include <QTextStream>
  11. #include <time.h>
  12. #include <windows.h>
  13. using namespace std;
  14.  
  15.  
  16.  
  17. const tm* timeinfos;
  18. void tray();
  19. void refresh();
  20. void starts();
  21. void wait();
  22. ofstream dif("d:\\dif.txt");
  23. const char* const path = "d:\\dif.txt" ;
  24. void starts();
  25. int hour=0,minu=0;
  26. ofstream times("d:\\time.txt");
  27. struct tm * timeinfo;
  28. time_t rawtime = time(0) ;
  29. int sec,secd;
  30. MainWindow w;
  31.  
  32.  
  33.  
  34. int main(int argc, char *argv[])
  35. {
  36. QApplication a(argc, argv);
  37. w.hide();
  38. std::thread first(tray);
  39. std::thread second(starts);
  40. std::thread third(refresh);
  41. starts();
  42. first.join();
  43. third.join();
  44.  
  45. return a.exec();
  46. }
  47.  
  48.  
  49. void tray(){
  50. QMenu *menu=new QMenu("TimeUsage");
  51. menu->addAction("Open");
  52. menu->addAction("Exit");
  53. trayIcon->setContextMenu(menu);
  54. trayIcon->setIcon(QIcon("e:\\icon.png"));
  55. trayIcon->show();
  56. trayIcon->showMessage("TimeUsage","TimeUsage Is Here!");
  57.  
  58. QObject::connect(menu,&QMenu::triggered,[&w](QAction* act){
  59.  
  60. const auto& text = act->text();
  61. if(text=="Exit"){
  62. QApplication::exit();
  63. }
  64. else if(text=="Open"){
  65. w.show();
  66. }
  67.  
  68.  
  69. });
  70. }
  71.  
  72.  
  73. void refresh(){
  74. for(;;){
  75. wait();
  76. time_t now = time(0) ;
  77. ifstream dif(path);
  78. time_t earlier = 0 ;
  79. dif >> earlier ;
  80.  
  81. double secs = difftime( now, earlier );
  82. minu=secs/60;
  83. while(minu>60){
  84. minu-=60;
  85. hour++;
  86. }
  87. QFile times("d:\\time.txt");
  88. times.open(QIODevice::Append);
  89. QTextStream stream(&times);
  90. stream<<asctime(timeinfos)<<endl<<hour<<"/"<<minu<<endl;
  91. }
  92. }
  93.  
  94.  
  95. void starts(){
  96. timeinfos = localtime ( &rawtime );
  97.  
  98. ofstream dif(path);
  99. dif << rawtime << '\n' ;
  100. dif.close();
  101. refresh();
  102. }
  103.  
  104.  
  105. void wait(){
  106. int i;
  107. for (i=0; i<=10; ++i) {
  108. this_thread::sleep_for (chrono::seconds(1));
  109. }
  110. }
To copy to clipboard, switch view to plain text mode 
the Program Has No Problem With Compiling But will Not Run And I Get the Following Error:
Untitled.png
Any Help Will Be Great