Utils::Guard Class
class Utils::GuardKlasa Guard implementira rekursivni guard s mehanizmom zaključavanja. Više...
| Header: | #include <Guard> |
Detaljan opis
Može se koristiti kao alternativa za QSignalBlocker. QSignalBlocker blokira sve signale objekta, što obično nije poželjno. Također može blokirati signale koji su potrebni samom objektu za internu upotrebu. Klase Guard i GuardLocker uopće ne blokiraju signale.
Kada pozivate metodu objekta koja može emitirati signal na koji ste priključeni, a želite zanemariti to obavještenje, trebali biste pohraniti objekt Guard kao član svoje klase i deklarirati objekt GuardLocker neposredno prije pozivanja navedene metode, na primjer:
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 }
Unutar slota koji je povezan s signalom objekta Guard možete provjeriti je li Guard zaključan i zanemariti daljnje operacije u tom slučaju:
void MyClass::otherObjectUpdated() { if (updateGuard.isLocked()) return; // we didn't trigger the update // so do update now \dots }
GuardLocker otključava Guard u svom destruktoru.
Objekt Guard je rekurzivan, možete deklarirati mnogo objekata GuardLocker za istu instancu Guarda i Guard će biti zaključan sve dok je barem jedan objekt GuardLocker stvoren za Guard u opsegu.
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.