PDA

View Full Version : Wishing my windows build wasn't so windows like



scwizard
24th February 2007, 21:27
On Linux when you store settings, they're usually stored in a INI text file. On OSX when you store settings, they're usually stored in a XML text file. Is there any way to make my windows build use one of those methods for manipulating settings instead of the awful registry?

On OSX when you go open up a QFileDialog::getOpenFileName the directory it starts in is set to the last directory you visited. Is there anyway to make my windows build behave like this? Preferably combining that with the text file settings mentioned above.

wysota
24th February 2007, 21:43
Pass IniFormat to a QSettings constructor variant that takes a format parameter.

As for the other question, the dialog takes a path to its starting directory as an argument. Simply store the last used path in some QString and use it here.

scwizard
24th February 2007, 22:01
Pass IniFormat to a QSettings constructor variant that takes a format parameter.
I can't belive I missed that, I guess my look over the QSettings docs was too cursory.


As for the other question, the dialog takes a path to its starting directory as an argument. Simply store the last used path in some QString and use it here.
My problem at first is that I wasn't sure how to fetch the last used path because I was caught up in thinking that it was a function. But then I realized it should be constructed on the stack in the same manner as message boxes. I have an idea of how to do it now.

scwizard
24th February 2007, 22:14
OK:
QFileDialog FileDialog(this, tr("Open File"), "C:\\", tr("Starcraft maps (*.scm *.scx *.chk);;All Files (*.*)"));
FileDialog.exec();
QString AString = FileDialog.directory().absolutePath();

Works like a charm. Except for the fact that it's giving me a Qt open file dialog instead of a native windows open file dialog. I see an option for DontUseNativeDialog, but I don't see an option for DoUseNativeDialog.

jpn
24th February 2007, 22:29
Use the static convenience function QFileDialog::getOpenFileName().

scwizard
24th February 2007, 22:31
And if I use that static convenience function, how the hell do I store the last used path in some QString?

jpn
24th February 2007, 22:51
You can use QFileInfo to get the path of the selected file.


QString path = <read from settings>
QString file = QFileDialog::getOpenFileName(.., path, ..);
if (!file.isNull())
{
path = QFileInfo(file).absolutePath();
<store path setting>
}

scwizard
24th February 2007, 22:57
Interesting, but is there a way to store the last visited directory even if the user presses the cancel button?

jpn
24th February 2007, 23:09
Interesting, but is there a way to store the last visited directory even if the user presses the cancel button?
No, unfortunately there is no way for that when using the static method.

scwizard
24th February 2007, 23:13
Is there any way to to store the last visited directory even if the user presses the cancel button AND use the native dialog?

jpn
25th February 2007, 00:23
Is there any way to to store the last visited directory even if the user presses the cancel button AND use the native dialog?
I'm afraid the static methods are the only ones for using native dialogs. So I'd say no..