Utils::Guard Class
class Utils::GuardRazred Guard implementira rekurzivni varovalni mehanizem z mehanizmom zaklepanja. Več...
| Header: | #include <Guard> |
Podroben opis
Lahko se uporablja kot alternativa razredu ` QSignalBlocker`. Razred ` QSignalBlocker ` blokira vse signale objekta, kar običajno ni zaželeno. Lahko blokira tudi signale, ki jih objekt sam potrebuje za notranje delovanje. Razreda `Guard` in `GuardLocker` sploh ne blokirata signalov.
Ko pokličete metodo objekta, ki lahko sproži signal, na katerega ste priključeni, in želite to obvestilo prezreti, morate objekt Guard ohraniti kot član razreda in objekt GuardLocker deklarirati tik pred klicem omenjene metode, na primer:
class MyClass : public QObject { \dots private: Guard updateGuard; // member of your class }; \dots void MyClass::updateOtherObject() { GuardLocker updatelocker(updateGuard); otherObject->update(); // this may trigger a signal }
Znotraj reže, ki je povezana s signalom drugega objekta, lahko preverite, ali je Guard zaklenjen, in v tem primeru prezrete nadaljnje operacije:
void MyClass::otherObjectUpdated() { if (updateGuard.isLocked()) return; // we didn't trigger the update // so do update now \dots }
GuardLocker odklene Guard v svojem destruktorju.
Objekt Guard je rekurziven; za isto instanco Guard lahko deklarirate več objektov GuardLocker, Guard pa bo zaklenjen, dokler bo v obsegu vsaj en objekt GuardLocker, ustvarjen za ta Guard.
Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.