PDA

View Full Version : Saving window set up using Qsettings



knobby67
21st August 2014, 16:27
Hi All,
hope you can help me out with this. I'm trying to save my window setting using the code below ( from a you tube tutorial). However whatever I try when I save the window and try to load it it's tiny. So to save I use


void MainWindow::GUI_savesettings( void )
{

QSettings settings("mysoft", "test");
settings.beginGroup("MainWindow");
settings.setValue( "position", this->geometry( ) );

settings.endGroup();


qDebug()<<"save";


}



and to load


void MainWindow::GUI_loadsettings( void )
{
QSettings settings("mysoft", "test");
settings.beginGroup("MainWindow");
QRect myrect = settings.value( "position " ).toRect();
setGeometry( myrect );
settings.endGroup();

}


When I debug I can set that in my load function myrect is set to postion,sizes 0,0,0,0.

I'm running Linux Lubuntu, could this be the cause? Or is there some error in my code? Or some mod to the way Qt handles this, I'm using 5.0.17
Thanks in advance.

Added after 23 minutes:

SOLVED
I copied the tutorial from http://contingencycoder.wordpress.com/2013/04/17/restoring-qt-application-state-and-geometry-part-2/
This works great

anda_skoa
21st August 2014, 16:36
You are using two different keys.

"position" for saving, "position " for reading

Cheers,
_