This is *so* lame... Trolltech needs to fix this issue, this is way wrong... anyway, this is what I am using right now (not very pleased with it, since the constructor now contains some text which should be part of the save function... which will make it hard to debug):
// somewhere in the constructor
extByMessage[ tr("Text files (*.txt *.utf8)") ] = ".txt";
extByMessage[ tr("HTML Files (*.html *.htm)") ] = ".html";
QHashIterator<QString, QString> i(extByMessage);
while (i.hasNext())
{
i.next();
saveMessage += i.key();
if (i.hasNext())
saveMessage += ";;";
}
// the save function
this,
tr("Choose a file to save to"),
lastDir,
saveMessage,
&sf
);
if (s.isEmpty())
return;
bool status;
// what if the users did not specify a suffix...?
if (f.suffix().isEmpty())
{
// http://www.qtcentre.org/forum/f-qt-programming-2/t-qfiledialoggetsavefilename-default-extension-8503.html
s += extByMessage[sf];
}
// somewhere in the constructor
extByMessage[ tr("Text files (*.txt *.utf8)") ] = ".txt";
extByMessage[ tr("HTML Files (*.html *.htm)") ] = ".html";
QHashIterator<QString, QString> i(extByMessage);
while (i.hasNext())
{
i.next();
saveMessage += i.key();
if (i.hasNext())
saveMessage += ";;";
}
// the save function
QString s = QFileDialog::getSaveFileName(
this,
tr("Choose a file to save to"),
lastDir,
saveMessage,
&sf
);
if (s.isEmpty())
return;
bool status;
// what if the users did not specify a suffix...?
QFileInfo f( s );
if (f.suffix().isEmpty())
{
// http://www.qtcentre.org/forum/f-qt-programming-2/t-qfiledialoggetsavefilename-default-extension-8503.html
s += extByMessage[sf];
}
To copy to clipboard, switch view to plain text mode
Bookmarks