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.
this,
"Choose a file to save to",
"",
"Text files (*.txt *.utf8);; HTML Files(*.html *.htm)",
&sf
);
if (s.isEmpty())
return;
bool status;
// what if the users did not specify a suffix...?
if (f.suffix().isEmpty())
{
//
qDebug("no suffix, adding %s", qPrintable( sf ) );
}
static QString sf;
QString s = QFileDialog::getSaveFileName(
this,
"Choose a file to save to",
"",
"Text files (*.txt *.utf8);; HTML Files(*.html *.htm)",
&sf
);
if (s.isEmpty())
return;
bool status;
QString s_lower = s.toLower();
// what if the users did not specify a suffix...?
QFileInfo f( s );
if (f.suffix().isEmpty())
{
//
qDebug("no suffix, adding %s", qPrintable( sf ) );
}
To copy to clipboard, switch view to plain text mode
Bookmarks