Qt Code:
  1. #include <QtCore>
  2. #include <QtGui>
  3.  
  4. class Window: public QMainWindow
  5. {
  6. public:
  7. Window(void):QMainWindow()
  8. {
  9. t=new QToolBar("Toolbar1",this);
  10. t->addAction(new QAction("Act1",this));
  11. t->addAction(new QAction("Act2",this));
  12. t->addAction(new QAction("Act3",this));
  13. addToolBar(t);
  14.  
  15. QSettings s("Trolltech","TestAPP");
  16. if(restoreState(s.value("MainWindowState").toByteArray()))
  17. {
  18. // creation of second toolbar depends on user interaction
  19. // for example second run
  20. t=new QToolBar("Toolbar2",this);
  21. t->addAction(new QAction("Act1",this));
  22. t->addAction(new QAction("Act2",this));
  23. t->addAction(new QAction("Act3",this));
  24. addToolBar(t);
  25. }
  26.  
  27. }
  28. ~Window(void)
  29. {
  30. QSettings s("Trolltech","TestAPP");
  31. s.setValue("MainWindowState",saveState());
  32. }
  33. private:
  34. };
  35.  
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39. QApplication app(argc, argv);
  40. Window window;
  41. window.show();
  42. return app.exec();
  43. }
To copy to clipboard, switch view to plain text mode 

why toolbars layout differently when state restored and when i dont use state restore function?