Hello!
Would you please tell me how to append filter text to filename as extension?

Found this solution:
http://www.qtcentre.org/forum/f-qt-p...ht=QFileDialog

but maybe there is a lighter one for such simple (I hope) operation?

Qt Code:
  1. void snapShot::on_actionSave_as_activated()
  2. {
  3. if ( preview->palette().brush ( backgroundRole() ).texture().isNull() )
  4. {
  5. QMessageBox::critical ( this,tr ( "Error" ),tr ( "Nothing to save" ),QMessageBox::Ok,0 );
  6. return;
  7. }
  8.  
  9. QString fName;
  10. QString frmts;
  11. QFileDialog fd ( this );
  12. fd.setAcceptMode ( QFileDialog::AcceptSave );
  13. fd.setWindowTitle ( tr ( "Save as..." ) );
  14.  
  15. QStringList filters ( fd.nameFilters() );
  16. filters << tr ( "PNG Images (*.png)" );
  17. filters << tr ( "JPG Images (*.jpg *.jpeg)" );
  18. filters << tr ( "XPM Images (*.xpm)" );
  19. filters << tr ( "All Images (*.png *.jpg *.jpeg *.xpm)" );
  20. fd.setNameFilters ( filters );
  21.  
  22. fd.setDirectory ( WorkDir );
  23. fd.setFileMode ( QFileDialog::AnyFile );
  24. if ( fd.exec() ==QDialog::Accepted )
  25. {
  26. QStringList files = fd.selectedFiles();
  27. if ( !files.isEmpty() )
  28. fName = files[0];
  29. }
  30. if ( fName.length() >0 )
  31. {
  32. if ( saveInFile ( fName ) ) {
  33.  
  34. if( !QFileInfo(fName).exists() )
  35. fName.append(".png");
  36. setWindowTitle( QFileInfo(fName).absoluteFilePath() + " - " + initWindowTitle);
  37. }
  38. }
  39. }
To copy to clipboard, switch view to plain text mode 

When the user print "file.jpg" - it's ok, but when he print just "file" and then choose filter ("jpg") - exec() returns "file" without any information about desired extension...

Thanks in advance!