Add the variable to the class inheriting QWidget and using the ui file instead of the ui file itself.