qt_weak_factory.h 827 B

123456789101112131415161718192021222324252627282930313233
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include <QtWidgets/QWidget>
  9. namespace Ui {
  10. template <typename Widget>
  11. QPointer<Widget> MakeWeak(Widget *object) {
  12. return QPointer<Widget>(object);
  13. }
  14. template <typename Widget>
  15. QPointer<const Widget> MakeWeak(const Widget *object) {
  16. return QPointer<const Widget>(object);
  17. }
  18. template <typename Widget>
  19. QPointer<Widget> MakeWeak(gsl::not_null<Widget*> object) {
  20. return QPointer<Widget>(object.get());
  21. }
  22. template <typename Widget>
  23. QPointer<const Widget> MakeWeak(gsl::not_null<const Widget*> object) {
  24. return QPointer<const Widget>(object.get());
  25. }
  26. } // namespace Ui