PDA

View Full Version : QSettings and Windows 7 64bit



JohnToddSr
10th May 2010, 20:20
The below code works just fine under Windows XP but fails to resize and move window under Windows 7 64bit.
I can not understand why. This is a dual monitor system. HELP!

void MainWindow::GetWindowSettings()
{
QSettings settings("C:/temp/temp.ini", QSettings::IniFormat);
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(800, 600)).toSize());
move(settings.value("pos", QPoint(5, 30)).toPoint());
settings.endGroup();
}

void MainWindow::SaveWindowSettings()
{
QSettings settings("C:/temp/temp.ini", QSettings::IniFormat);
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
settings.sync();
}

The settings are saved and read back in as I have tested that. However, the move and resize do not happed!!

MorrisLiang
11th May 2010, 02:48
I would use

QSettings settings(qApp->applicationDirPath() + "/setting.ini",QSettings::IniFormat);
settings.setValue("Main/Geometry", saveGeometry());

and

QSettings settings(qApp->applicationDirPath() + "/setting.ini",QSettings::IniFormat);
restoreGeometry(settings.value("Main/Geometry").toByteArray());

It works for me,in windows7,but 32bit

JohnToddSr
11th May 2010, 20:57
I really appreciate the response.
First let me say it had nothing to do with Windows 7 64bit!

This is what caused the problem:

-----In main.cpp-----------------------------------------------------------------------------
int main(int argc, char ** argv)
{
.
.
win.setGeometery(0, 0, 800, 600);
win.show();
.
.
}
-----In MainWindow.cpp-----------------------------------------------------------------------------
MainWindow::MainWindow( QWidget * parent, Qt::WFlags f) : QMainWindow(parent, f)
{
.
.
GetWindowsSettings();
setupUi(this);
.
.
}

Making the call to win.setGeometery() was the issue.
Not sure why but it is one of those things that really
doesn't matter at the moment.

Anyone have any thoughts on this?

Zlatomir
11th May 2010, 21:06
If you copy/pasted the code, you have a typo: win.setGeometEry(...)
And if your code has correct name, check/debug the code, because i tested win.setGeometry(..) and it works on 7 64bit.

MorrisLiang
12th May 2010, 03:01
I think I might know what's going wrong.
So you construct an object of MainWindow,in the constructor,you call GetWindowsSettings() to set its geometry thing.
After the construction you also call

win.setGeometery(0, 0, 800, 600);
so,setGeometery() overrides GetWindowsSettings() which makes GetWindowsSettings() useless.

Perhaps you want to make sure it's 800*600 when the app first run.

void MainWindow::GetWindowSettings()
{
QSettings settings("C:/temp/temp.ini", QSettings::IniFormat);
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(800, 600)).toSize());
move(settings.value("pos", QPoint(5, 30)).toPoint());
settings.endGroup();
}
In GetWindowSettings(),you have already provided a default value.If the app cannot find the temp.ini.It will resize to 800*600.So,actually you don't have to call setGeometery().