https://qt6.jp/2020/03/qscopeguard/
スコープが終わった際に処理をしたい