Save and Restore dockwidgets position and size
<p>I can't quite figure out how the save and restore are suppose to work, so that I may save the dockwidgets geometrics, when the application is closed and opened again. I have 5 dockwidgets, which I'd like to have this feature.</p>

<p>I assume I have to use both <code>restoreState</code> and <code>saveState</code> respectively in <code>init</code> and <code>close</code>. But how do I configure it?</p>

<p>MainWindow class</p>

<pre><code>import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from DockWindowGraph import Dock

class Window(QMainWindow):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)

        self.centralWindow_ = QFrame() 
        self.setCentralWidget(None)

        self.CreateWidgets()

        self.settings = QSettings()
        self.restoreState()

    def CreateWidgets(self):        
        self.toolbar = self.addToolBar('Toolbar')
        self.toolbar.setMovable(False)    

        exitA = QAction(QIcon('Images/gj.png'), 'Exit', self)
        exitA.setShortcut('Ctrl+Q')
        exitA.setStatusTip('Exit application')
        exitA.triggered.connect(self.close)   
        self.toolbar.addAction(exitA)

        openDock_ = QAction(QIcon('Images/gj.png'), 'Open', self)
        openDock_.setShortcut('Ctrl+E')
        openDock_.setStatusTip('Open Dock')
        openDock_.triggered.connect(self.OpenDockWindow)   
        self.toolbar.addAction(openDock_)

        self.setWindowTitle("We do not sow")
        self.showFullScreen()

        self.firstDock_ = Dock(self, 'First')
        self.firstDock_.setObjectName('First')
        self.addDockWidget(Qt.LeftDockWidgetArea, self.firstDock_)     

        self.secondDock_ = Dock(self, 'Second')
        self.firstDock_.setObjectName('Second')
        self.addDockWidget(Qt.LeftDockWidgetArea, self.secondDock_)

        self.thirdDock_ = Dock(self, 'Third')
        self.thirdDock_.setObjectName('Third')
        self.splitDockWidget(self.firstDock_, self.thirdDock_, Qt.Horizontal)

        self.fDock_ = Dock(self, 'Fourth')
        self.fDock_.setObjectName('Fourth')
        self.splitDockWidget(self.firstDock_, self.fDock_, Qt.Horizontal)

        self.fiDock_ = Dock(self, 'Fifth')
        self.fiDock_.setObjectName('Fifth')
        self.splitDockWidget(self.firstDock_, self.fiDock_, Qt.Vertical)

        self.setTabPosition(Qt.AllDockWidgetAreas, QTabWidget.North)

    def OpenDockWindow(self):
        dock_ = Dock((self.frameGeometry().width() / 2), self.firstDock_)

        self.addDockWidget(Qt.RightDockWidgetArea, dock_)
        self.tabifyDockWidget(self.secondDock_, dock_)

    def closeEvent(self, event):
        print('closing')

        settings_ = QSettings()
        self.saveState()


app = QApplication(sys.argv)
app.setOrganizationDomain('ltd')
app.setOrganizationName('Alg')
w = Window()
sys.exit(app.exec_())
</code></pre>

<p>my Dock class:</p>

<pre><code>from PyQt4.QtCore import *
from PyQt4.QtGui import *
from DockWindowFrame import Frame

class Dock(QDockWidget):
    def __init__(self, title, parent=None):
        super(Dock, self).__init__(parent)

        self.setAllowedAreas(Qt.RightDockWidgetArea | Qt.LeftDockWidgetArea | Qt.TopDockWidgetArea | Qt.BottomDockWidgetArea)
        self.setFeatures(QDockWidget.DockWidgetFloatable | QDockWidget.DockWidgetMovable )

        self.frame = Frame()
        self.frame.setStyleSheet("QWidget { background-color: rgba(0,220,0,100%)}")
        self.setWidget(self.frame)

    def ReturnFrame(self):
        return self.frame
</code></pre>

<p>EDIT: Error after trying below answer.</p>

<pre><code>Traceback (most recent call last):
  File "C:\Users\Rasmus\workspace\PyQtLearning\src\gg.py", line 90, in &lt;module&gt;
    main()
  File "C:\Users\Rasmus\workspace\PyQtLearning\src\gg.py", line 86, in main
    w = Window()
  File "C:\Users\Rasmus\workspace\PyQtLearning\src\gg.py", line 14, in __init__
    self.readSettings()
  File "C:\Users\Rasmus\workspace\PyQtLearning\src\gg.py", line 72, in readSettings
    self.restoreGeometry(settings.value("geometry").toByteArray())
AttributeError: 'NoneType' object has no attribute 'toByteArray'
</code></pre>