Remove code duplication. Change-Id: Ib1859f2c3a04f66d0f0b669b4e93a7fc06ab8e61 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>