MainWidget* mainWindow = nullptr; foreach (QWidget *w, qApp->topLevelWidgets()){ if (MainWidget* mainWidget = qobject_cast<MainWidget*>(w)) mainWindow = mainWidget; }