Port code to Qt5