#include "mainDialog.h"#include <QLabel>#include <QTimer>#include <QHBoxLayout>#include <QIcon>#include <QSystemTrayIcon>MainDialog::MainDialog(QDialog *parent) : QDialog(parent){ trayIcon = new QSystemTrayIcon(this); QIcon icon = QIcon("icon.png"); trayIcon->setIcon(icon); setWindowIcon(icon); trayIcon->show(); j=0; label = new QLabel(this); label->setText(tr("Start")); timer = new QTimer(this); timer->setSingleShot(true); connect(timer, SIGNAL(timeout()), this, SLOT(updates())); //В диалоговое окно добавили лейбел для отображения. QHBoxLayout *labelLayout = new QHBoxLayout; labelLayout->addWidget(label); setLayout(labelLayout);}void MainDialog::updates(){ j++; label->setText(QString::number(j)); update();}void MainDialog::SetText(QString text){ label->setText(text);}void MainDialog::StartTimer(int timeout){ timer->start(timeout);}void MainDialog::StopTimer(){ timer->stop();}
MainDialog *myDialog;DWORD func(LPVOID lpvoid){myDialog->StartTimer(200);}int main(int argc, char *argv[]){ HANDLE hReadThread = NULL; DWORD dwThreadID; QApplication a(argc, argv); myDialog = new MainDialog(); myDialog->resize(240,50); myDialog->show(); if (hReadThread = CreateThread (NULL, 0, func, 0, 0, &dwThreadID)) { CloseHandle (hReadThread); } return a.exec();}
C++ (Qt)QApplication a(argc, argv);QErrorMessage::qtHandler();
C++ (Qt)if (hReadThread = CreateThread (NULL, 0, func, 0, 0, &dwThreadID)) { CloseHandle (hReadThread); }
C++ (Qt)QMetaObject::invokeMethod( timer, "start", Qt::QueuedConnection );