Cannot hide tool bars and module panel

I am developing a custom app and want to hide slicer’s tool bars and module panel.
Inside the qXXAppMainWindowPrivate::setupUi function , I added several lines at the bottom

  auto modulePanel = mainWindow->findChildren<QDockWidget*>();
  auto toolbars = mainWindow->findChildren<QToolBar*>();
  modulePanel.at(0)->setVisible(false);
  for(int i=0;i<toolbars.count();i++)
  {
    toolbars.at(i)->setVisible(false);
  }

which should hide the module panel and toolbars, however,
Every time I start the app the module panel and toolbars still exists.

What is the problem during startup? Since python api like setToolbarsVisible works fine with this.

Operating system: ubuntu 18.04
Slicer version: v5.0.3