philw
28th March 2009, 09:00
With the use of the static QFileDialog getSaveFileName() method -- if the file chosen by user already exists, the user is given the choice of not overwriting that file. (This is with Qt 4.3.3).
http://www.thirdtablet.com/cadswes/2009/TextOutput/screenshots/OverwriteFileConfirm.png
However, there doesn't seem to be a way for the caller to know that the user made that choice (of aborting the save operation, being that the file already exists).
When the user CANCELS the selection operation (before making the selection), an empty string is returned as the file path result. An empty string should probably also be the result in the case of the user overwrite denial. But it isn't. See code sample, below.
Is there a well known global entity to check for this user response? Currently this is an unavoidable bug: the file gets overwritten regardless of the user's choice !!!
Test code:
...
static const QString caption ("Select Report Output File");
QString startPathStr = ... // details omitted
static QString selectedFilter ("");
static const QString filter ("HTML (*.htm *.html);;"
"TEXT (*.txt);;"
"All (*)");
// **************************************************
// *** Show and Execute Save File Path Selector ***
// **************************************************
const QString userPickedPath =
QFileDialog::getSaveFileName (NULL, // parent widget
caption,
startPathStr,
filter,
&selectedFilter);
const bool userPickedEmpty (userPickedPath.isEmpty());
std::cout << " Picked: '" << qPrintable (userPickedPath) << "' "
<< (userPickedEmpty ? "[EMPTY]" : "[GOOD TO GO]")
<< std::endl;
if (userPickedEmpty)
{
// File selection canceled by user.
return (false);
//----------->>
}
setReportPath (userPickedPath);
return (true);
//---------->>
Thank you in advance,
Phil Weinstein, CADSWES
http://cadswes.colorado.edu/
http://www.thirdtablet.com/cadswes/2009/TextOutput/screenshots/OverwriteFileConfirm.png
However, there doesn't seem to be a way for the caller to know that the user made that choice (of aborting the save operation, being that the file already exists).
When the user CANCELS the selection operation (before making the selection), an empty string is returned as the file path result. An empty string should probably also be the result in the case of the user overwrite denial. But it isn't. See code sample, below.
Is there a well known global entity to check for this user response? Currently this is an unavoidable bug: the file gets overwritten regardless of the user's choice !!!
Test code:
...
static const QString caption ("Select Report Output File");
QString startPathStr = ... // details omitted
static QString selectedFilter ("");
static const QString filter ("HTML (*.htm *.html);;"
"TEXT (*.txt);;"
"All (*)");
// **************************************************
// *** Show and Execute Save File Path Selector ***
// **************************************************
const QString userPickedPath =
QFileDialog::getSaveFileName (NULL, // parent widget
caption,
startPathStr,
filter,
&selectedFilter);
const bool userPickedEmpty (userPickedPath.isEmpty());
std::cout << " Picked: '" << qPrintable (userPickedPath) << "' "
<< (userPickedEmpty ? "[EMPTY]" : "[GOOD TO GO]")
<< std::endl;
if (userPickedEmpty)
{
// File selection canceled by user.
return (false);
//----------->>
}
setReportPath (userPickedPath);
return (true);
//---------->>
Thank you in advance,
Phil Weinstein, CADSWES
http://cadswes.colorado.edu/