I have file.txt. I type "file" in my filedialog, and I get error - "file is not found" i. How to add to "file" default extension? For example, .txt.
my filedialog is:
QFileDialog::getOpenFileName(this, "title", "text", "Text Files(*.txt));
I have file.txt. I type "file" in my filedialog, and I get error - "file is not found" i. How to add to "file" default extension? For example, .txt.
my filedialog is:
QFileDialog::getOpenFileName(this, "title", "text", "Text Files(*.txt));
Last edited by somename; 26th May 2010 at 15:46.
Checkout the QFileDialog::setDefaultSuffix() method
You have to run a level 3 diagnostic.
Ashes to ashes, Qt to Qt ( wysota )
Or something like this:
Qt Code:
"", tr("Plain text file (*.txt)"));To copy to clipboard, switch view to plain text mode
I try this:
- QFileDialog *fileDialog = new QFileDialog;
- fileDialog->setDefaultSuffix("txt");
- QString some = fileDialog->getOpenFileName(this, "title", "text", "Text Files(*.txt));
but I get same message : "file not found" when I type "file" without extension .txt
I get now what You want to do.
So You need to do an extra work to get this to work the way you want it to.
First:
then declare slot i.e. slotSel(QString). This will bring a QT FileDialog, not the SYSTEM!.Qt Code:
To copy to clipboard, switch view to plain text mode
When You type i.e. 1 full path will be returned in slot
i.e.:
And here You can do whatever You want with the string path.Qt Code:
{ qDebug() << fileNameAndPath; }To copy to clipboard, switch view to plain text mode
ok, but why setDefaultSuffix does not working?
Probably because of getOpenFileName. To be honest I don't know why setting fileMode to Any don't allow that. Maybe someone will know how to do that "easy way".
The old Qt3 file dialog let the user type in the filter combo box. The Qt4 dialog made the combo box non-editable, and also did away with the ability to preview files. Both represent a giant step backward.
I contacted Qt about this, and their "solution" is to rummage around in the QFileDialog class and change the combo box to editable, a procedure that is less than ideal but which works. Their solution looks like this:
Qt Code:
if (cb) cb->setEditable(true);To copy to clipboard, switch view to plain text mode
where 'this' is the QFileDialog; the code shown is executed in the constructor of a file dialog derived from QFileDialog.
Obviously, if the trolls ever change the name of the combo box, this method will fail. But they assure me this is unlikely. They also said that my request to have both the preview and the ability to allow users to add their own filters at runtime will be brought to the attention of the maintainers, but there were no promises that we would see these features return.
My English is too bad.. Maybe you don't understand me?
Now, I have question about this..
QFileDialog *fileDialog = new QFileDialog;
fileDialog->setFileMode( QFileDialog::AnyFile );
fileDialog->open( this, SLOT(slotSel(QString)) );
void MainWindow::slotSel( QString fileNameAndPath)
{
qDebug() << fileNameAndPath;
}
it works, but it don't use native dialogs!!!
Is there some way to use native dialogs and set default extension?
The "trick" here is to use Qt File Dialog, because native implementation don't allow You to do what You want. And the "actual problem" is with disabling file check.
Of course nothing stops You from using WinAPI, but the code will not be portable. Look for example here: http://msdn.microsoft.com/en-us/library/ms646927 .
Bookmarks