Instead of creating a new action, simply 6 get the action from the QDockWidget itself 5 and use that. It'll take care of state for 4 you:
QAction * QDockWidget::toggleViewAction () const
"Returns a checkable action that 3 can be used to show or close this dock widget.
The 2 action's text is set to the dock widget's 1 window title. "
More Related questions