C++ (Qt) class QTimer; class ControlEngine : public QWidget, public QAxBindable { Q_OBJECT public: ControlEngine::ControlEngine(QWidget *parent) : QWidget(parent) , timer(new QTimer(this)) { qDebug() << Q_FUNC_INFO; connect(timer, SIGNAL(timeout()), this, SLOT(timeout())); timer->start(1000); } ControlEngine::~ControlEngine() { qDebug() << Q_FUNC_INFO; } QAxAggregated *ControlEngine::createAggregate() { qDebug() << Q_FUNC_INFO; return new ProviderImpl(); } private slots: void timeout() { qDebug() << Q_FUNC_INFO; } private: QPointer<QTimer> timer; }; QAXFACTORY_DEFAULT( ControlEngine, "{FCF395FC-B5AB-40A9-B632-09693DF21D86}", ... ... )
connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
bool tmp = connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));qDebug() << tmp;
C++ (Qt)static HHOOK my_hook = 0; static LRESULT QT_WIN_CALLBACK MyProc(int nCode, WPARAM wParam, LPARAM lParam){ if (qApp) qApp->processEvents(); return ::CallNextHookEx(my_hook, nCode, wParam, lParam);} ControlEngine::ControlEngine(QWidget *parent) : QWidget(parent) , timer(new QTimer(this)){ qDebug() << Q_FUNC_INFO; my_hook = ::SetWindowsHookEx(WH_GETMESSAGE, MyProc, 0, ::GetCurrentThreadId()); qDebug() << Q_FUNC_INFO << "my_hook" << my_hook; QObject::connect(timer, SIGNAL(timeout()), this, SLOT(timeout())); timer->start(1000);} ControlEngine::~ControlEngine(){ if (my_hook) ::UnhookWindowsHookEx(my_hook); qDebug() << Q_FUNC_INFO;}
C++ (Qt)// callback for DLL server to hook into non-Qt eventloopLRESULT QT_WIN_CALLBACK axs_FilterProc(int nCode, WPARAM wParam, LPARAM lParam){ if (qApp && !invokeCount) qApp->sendPostedEvents(); return CallNextHookEx(qax_hhook, nCode, wParam, lParam);}