diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2018-12-05 11:45:36 +0100 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2018-12-06 06:30:57 +0000 |
commit | b3b387698e8f685e8bd4f4843a170da40e17249b (patch) | |
tree | a1027fa8a541804d3c54bd95756b270b2848ba52 /src | |
parent | 65bea2ce743d628773591793d35f2048fda5820a (diff) |
qnearfieldmanager_emulator: Use Q_GLOBAL_STATIC for tag activator
Using a Q_GLOBAL_STATIC here fixes an issue in the auto tests for winrt.
If we use a static object that is created before the QCoreapplication has
been created, TagActivator's timer will complain, that it was not created
inside a QThread.
By postponing the creation until first usage we can avoid that problem.
Change-Id: I9beca89930bfca2c71e0fce3d9c000dfcb71f431
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/nfc/qnearfieldmanager_emulator.cpp | 10 | ||||
-rw-r--r-- | src/nfc/qnearfieldtarget_emulator.cpp | 6 | ||||
-rw-r--r-- | src/nfc/qnearfieldtarget_emulator_p.h | 2 |
3 files changed, 6 insertions, 12 deletions
diff --git a/src/nfc/qnearfieldmanager_emulator.cpp b/src/nfc/qnearfieldmanager_emulator.cpp index c2c037f6..8a61a3a9 100644 --- a/src/nfc/qnearfieldmanager_emulator.cpp +++ b/src/nfc/qnearfieldmanager_emulator.cpp @@ -49,12 +49,10 @@ QT_BEGIN_NAMESPACE QNearFieldManagerPrivateImpl::QNearFieldManagerPrivateImpl() { - TagActivator *tagActivator = TagActivator::instance(); + globalTagActivator->initialize(); - tagActivator->initialize(); - - connect(tagActivator, &TagActivator::tagActivated, this, &QNearFieldManagerPrivateImpl::tagActivated); - connect(tagActivator, &TagActivator::tagDeactivated, this, &QNearFieldManagerPrivateImpl::tagDeactivated); + connect(globalTagActivator, &TagActivator::tagActivated, this, &QNearFieldManagerPrivateImpl::tagActivated); + connect(globalTagActivator, &TagActivator::tagDeactivated, this, &QNearFieldManagerPrivateImpl::tagDeactivated); } QNearFieldManagerPrivateImpl::~QNearFieldManagerPrivateImpl() @@ -68,7 +66,7 @@ bool QNearFieldManagerPrivateImpl::isAvailable() const void QNearFieldManagerPrivateImpl::reset() { - TagActivator::instance()->reset(); + globalTagActivator->reset(); } void QNearFieldManagerPrivateImpl::tagActivated(TagBase *tag) diff --git a/src/nfc/qnearfieldtarget_emulator.cpp b/src/nfc/qnearfieldtarget_emulator.cpp index 996ddcef..0723b655 100644 --- a/src/nfc/qnearfieldtarget_emulator.cpp +++ b/src/nfc/qnearfieldtarget_emulator.cpp @@ -51,7 +51,6 @@ QT_BEGIN_NAMESPACE static QMutex tagMutex; static QMap<TagBase *, bool> tagMap; -static TagActivator tagActivator; TagType1::TagType1(TagBase *tag, QObject *parent) : QNearFieldTagType1(parent), m_tag(tag) @@ -248,11 +247,6 @@ void TagActivator::reset() tagMap.clear(); } -TagActivator *TagActivator::instance() -{ - return &tagActivator; -} - void TagActivator::timerEvent(QTimerEvent *e) { Q_UNUSED(e); diff --git a/src/nfc/qnearfieldtarget_emulator_p.h b/src/nfc/qnearfieldtarget_emulator_p.h index 70a67be8..1b9f7bdb 100644 --- a/src/nfc/qnearfieldtarget_emulator_p.h +++ b/src/nfc/qnearfieldtarget_emulator_p.h @@ -122,6 +122,8 @@ private: int timerId; }; +Q_GLOBAL_STATIC(TagActivator, globalTagActivator); + QT_END_NAMESPACE #endif // QNEARFIELDTARGET_EMULATOR_P_H |