I want to add a extension to the file name a user chooses. Lets assume the piece of code attached. Lets also assume that the user chooses to save as "html", and he chooses the filename "file1".

I want to add to the filename, the "html" extension. However, on my code the variable sf contains the full string showed at the bottom 'HTML Files(*.html *.htm)' and I just want "html".

I can handcraft something myself, like having a hash, and creating the string to be passed to the QFileDialog::getSaveFileName call, but I am hoping for a better tirck.


Qt Code:
  1. static QString sf;
  2. QString s = QFileDialog::getSaveFileName(
  3. this,
  4. "Choose a file to save to",
  5. "",
  6. "Text files (*.txt *.utf8);; HTML Files(*.html *.htm)",
  7. &sf
  8. );
  9.  
  10. if (s.isEmpty())
  11. return;
  12.  
  13. bool status;
  14. QString s_lower = s.toLower();
  15.  
  16. // what if the users did not specify a suffix...?
  17. QFileInfo f( s );
  18. if (f.suffix().isEmpty())
  19. {
  20. //
  21. qDebug("no suffix, adding %s", qPrintable( sf ) );
  22. }
To copy to clipboard, switch view to plain text mode