--- a/src/gui/widgets/qdockarealayout.cpp
+++ b/src/gui/widgets/qdockarealayout.cpp
@@ -1829,7 +1829,7 @@ void QDockAreaLayoutInfo::saveState(QDataStream &stream) const
             }
         } else if (item.placeHolderItem != 0) {
             stream << (uchar) WidgetMarker;
-            stream << item.placeHolderItem->objectName;
+            stream << item.placeHolderItem->objectName + QLatin1String("qplaceholderitem");
             uchar flags = 0;
             if (!item.placeHolderItem->hidden)
                 flags |= StateFlagVisible;
@@ -1901,9 +1901,14 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*>
         uchar nextMarker;
         stream >> nextMarker;
         if (nextMarker == WidgetMarker) {
+            bool isPlaceHolder = false;
             QString name;
             uchar flags;
             stream >> name >> flags;
+            if (name.endsWith(QLatin1String("qplaceholderitem"))) {
+                isPlaceHolder = true;
+                name = name.remove(QLatin1String("qplaceholderitem"));
+            }
             if (name.isEmpty()) {
                 int dummy;
                 stream >> dummy >> dummy >> dummy >> dummy;
@@ -1917,11 +1922,9 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*>
                     break;
                 }
             }
-
-            if (widget == 0) {
+            if (widget == 0 || (widget && isPlaceHolder)) {
                 QPlaceHolderItem *placeHolder = new QPlaceHolderItem;
                 QDockAreaLayoutItem item(placeHolder);
-
                 placeHolder->objectName = name;
                 placeHolder->window = flags & StateFlagFloating;
                 placeHolder->hidden = !(flags & StateFlagVisible);
@@ -1935,8 +1938,11 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*>
                 }
                 if (item.size != -1)
                     item.flags |= QDockAreaLayoutItem::KeepSize;
-                if (!testing)
+                if (!testing) {
                     item_list.append(item);
+                    if (widget)
+                        mainWindow->removeDockWidget(widget);
+                }
             } else {
                 QDockAreaLayoutItem item(new QDockWidgetItem(widget));
                 if (flags & StateFlagFloating) {
@@ -1988,10 +1994,11 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*>
                         emit widget->dockLocationChanged(toDockWidgetArea(dockPos));
                     }
                 }
-		if (testing) {
-		  //was it is not really added to the layout, we need to delete the object here
-		  delete item.widgetItem;
-		}
+                if (testing) {
+                    //was it is not really added to the layout, we need to delete the object here
+                    delete item.placeHolderItem;
+                    delete item.widgetItem;
+                }
             }
         } else if (nextMarker == SequenceMarker) {
             int dummy;

--- a/src/gui/widgets/qmainwindowlayout.cpp
+++ b/src/gui/widgets/qmainwindowlayout.cpp
@@ -693,22 +693,6 @@ bool QMainWindowLayoutState::restoreState(QDataStream &_stream,
                     QList<QDockWidget *> dockWidgets = findChildrenHelper<QDockWidget*>(mainWindow);
                     if (!dockAreaLayout.restoreState(stream, dockWidgets))
                         return false;
-
-                    for (int i = 0; i < dockWidgets.size(); ++i) {
-                        QDockWidget *w = dockWidgets.at(i);
-                        QList<int> path = dockAreaLayout.indexOf(w);
-                        if (path.isEmpty()) {
-                            QList<int> oldPath = oldState.dockAreaLayout.indexOf(w);
-                            if (oldPath.isEmpty()) {
-                                continue;
-                            }
-                            QDockAreaLayoutInfo *info = dockAreaLayout.info(oldPath);
-                            if (info == 0) {
-                                continue;
-                            }
-                            info->item_list.append(QDockAreaLayoutItem(new QDockWidgetItem(w)));
-                        }
-                    }
                 }
                 break;
 #endif // QT_NO_DOCKWIDGET
