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):

Qt Code:
  1. // somewhere in the constructor
  2. extByMessage[ tr("Text files (*.txt *.utf8)") ] = ".txt";
  3. extByMessage[ tr("HTML Files (*.html *.htm)") ] = ".html";
  4.  
  5. QHashIterator<QString, QString> i(extByMessage);
  6. while (i.hasNext())
  7. {
  8. i.next();
  9. saveMessage += i.key();
  10. if (i.hasNext())
  11. saveMessage += ";;";
  12. }
  13.  
  14. // the save function
  15. QString s = QFileDialog::getSaveFileName(
  16. this,
  17. tr("Choose a file to save to"),
  18. lastDir,
  19. saveMessage,
  20. &sf
  21. );
  22.  
  23. if (s.isEmpty())
  24. return;
  25.  
  26. bool status;
  27.  
  28. // what if the users did not specify a suffix...?
  29. QFileInfo f( s );
  30. if (f.suffix().isEmpty())
  31. {
  32. // http://www.qtcentre.org/forum/f-qt-programming-2/t-qfiledialoggetsavefilename-default-extension-8503.html
  33. s += extByMessage[sf];
  34. }
To copy to clipboard, switch view to plain text mode