The main idea is to have time shown on Qtable (is there a better class for it?) on main widget. At first the time is updated correctly every second, but after ~10 seconds the time is updated only every 2, 3, etc seconds. Now I think for some reason something makes the program slow down, and for that the clock is updated more infrequent. There may be some loop that i cant notice that continues to eat up the resources more and more after each update:

Qt Code:
  1. class test : public QObject
  2. {
  3. Q_OBJECT
  4. public:
  5. test(QWidget *qwi,QLabel *qlb);
  6.  
  7. public slots:
  8. void upd();
  9.  
  10. private:
  11. QWidget *qw;
  12. QLabel *ql;
  13. };
  14.  
  15. test::test(QWidget *qwi, QLabel *qlb)
  16. {
  17. qw = qwi;
  18. ql = qlb;
  19. }
  20.  
  21. void test::upd()
  22. {
  23. QTimer *timer = new QTimer();
  24. connect(timer,SIGNAL(timeout()),this,SLOT(upd()));
  25. timer->start(1000);
  26. QTime time = QTime::currentTime();
  27. QString str = "<font color='green'>";
  28. str.append(time.toString("hh:mm:ss"));
  29. str.append("</font>");
  30. ql->setText(str);
  31. qw->update();
  32. }
  33.  
  34.  
  35. int main (int argc, char *argv[])
  36. {
  37. QApplication app(argc, argv);
  38.  
  39. QWidget window;
  40.  
  41. window.resize(1024, 768);
  42. QLabel *timeLabel = new QLabel(&window);
  43. timeLabel->setFrameStyle(QFrame::NoFrame | QFrame::Plain);
  44. timeLabel->setFont(QFont("Times", 20, QFont::Bold));
  45. timeLabel->setAlignment(Qt::AlignBottom | Qt::AlignRight);
  46. QString str = "<font color='green'>";
  47. QTime time = QTime::currentTime();
  48. str.append(time.toString("hh:mm:ss"));
  49. str.append("</font>");
  50. timeLabel->setText(str);
  51.  
  52. QPalette palette(QApplication::palette());
  53. window.setParent(0,Qt::FramelessWindowHint);
  54. palette.setColor(QPalette::Background, QColor("Black"));
  55. QPushButton quit("Quit", &window);
  56. quit.setFont(QFont("Times", 18, QFont::Bold));
  57. palette.setColor(QPalette::Button, QColor("Blue"));
  58. window.setPalette(palette);
  59. quit.setPalette(palette);
  60. quit.setGeometry(974, 0, 50, 20);
  61. QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
  62.  
  63.  
  64. window.show();
  65.  
  66. test *t = new test(&window,timeLabel);
  67. t->upd();
  68. return app.exec();
  69. }
  70.  
  71. #include "main.moc"
To copy to clipboard, switch view to plain text mode