Skip to content

Instantly share code, notes, and snippets.

@edulix
Created September 26, 2011 14:58
Show Gist options
  • Save edulix/1242425 to your computer and use it in GitHub Desktop.
Save edulix/1242425 to your computer and use it in GitHub Desktop.
state is not restored correctly
project(testguiapp)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 REQUIRED)
include_directories(${QT_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR})
set(testguiapp_SRCS testguiapp.cpp main.cpp)
qt4_automoc(${testguiapp_SRCS})
add_executable(testguiapp ${testguiapp_SRCS})
target_link_libraries(testguiapp ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY})
#include <QtGui/QApplication>
#include "testguiapp.h"
int main(int argc, char** argv)
{
QApplication app(argc, argv);
testguiapp foo;
foo.show();
return app.exec();
}
#include "testguiapp.h"
#include <QtGui/QLabel>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QAction>
#include <QDockWidget>
#include <QToolBar>
#include <QDebug>
testguiapp::testguiapp()
{
resize(400, 500);
QToolBar* toolbar = new QToolBar(this);
toolbar->setObjectName("toolbar");
QAction* a = new QAction(this);
a->setText( "save" );
connect(a, SIGNAL(triggered()), this, SLOT(save()));
toolbar->addAction(a);
a = new QAction(this);
a->setText( "restore" );
connect(a, SIGNAL(triggered()), this, SLOT(restore()));
toolbar->addAction(a);
addToolBar(toolbar);
createGui();
}
testguiapp::~testguiapp()
{}
void testguiapp::save()
{
qDebug() << "save";
mState = saveState();
}
void testguiapp::createGui()
{
mLabel = new QLabel(this);
mLabel->setText("Hello World!");
mLabel->setObjectName("mainwidget");
setCentralWidget(mLabel);
mLeftDock = new QDockWidget(this);
mLeftDock->setObjectName("leftdock");
QLabel* label = new QLabel(mLeftDock);
label->setObjectName("labelDock");
addDockWidget(Qt::RightDockWidgetArea, mLeftDock);
mLeftDock->setWidget(label);
}
void testguiapp::deleteGui()
{
delete mLabel;
delete mLeftDock;
mLabel = 0;
mLeftDock = 0;
}
void testguiapp::restore()
{
qDebug() << "restore";
deleteGui();
createGui();
restoreState(mState);
}
#include "testguiapp.moc"
#ifndef testguiapp_H
#define testguiapp_H
#include <QtGui/QMainWindow>
#include <QLabel>
#include <QDockWidget>
class testguiapp : public QMainWindow
{
Q_OBJECT
public:
testguiapp();
virtual ~testguiapp();
protected Q_SLOTS:
void save();
void restore();
protected:
void createGui();
void deleteGui();
private:
QByteArray mState;
QLabel* mLabel;
QDockWidget* mLeftDock;
QByteArray mWidgetState;
QByteArray mCentralWidgetState;
};
#endif // testguiapp_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment