I came across the same problem today, and I used the method introduced here: How to nicely "cast" qint64 to int for QProgressBar,
Regarding your solution, it probably works well most of the time, but since qint64 is 64-bit and int is mostly 32-bit, the value for the slider could be overflowed. Setting percentage values may be safer.