[Qt-interest] QFileDialog::getOpenFileName Directory name

Malyushytsky, Alex alex at wai.com
Wed Jun 9 23:41:57 CEST 2010


>From Qt documentation:

"QString QFileDialog::getOpenFileName ( QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0 )   [static]

This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns a null string.

 QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
                                                 "/home",
                                                 tr("Images (*.png *.xpm *.jpg)"));"

I can bet "/home" is not file. But I guess if home did not exist, dialog would treat it as a file name.

My point was to check if he actually the path mentioned in the directory name exist.
If the pass is relative and coed runs from different locations path can't be found in one case,
and problem has nothing to do with the way string is passed to static function.

Sorry if it was not clear.

Alex



-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of K. Frank
Sent: Tuesday, June 08, 2010 6:58 PM
To: Qt-interest
Subject: Re: [Qt-interest] QFileDialog::getOpenFileName Directory name

Hello Alex -

On Tue, Jun 8, 2010 at 6:27 PM, Malyushytsky, Alex <alex at wai.com> wrote:
> If you are sure you get such behavior ( I would suggest place call right after another in your test case to verify )   it might be possible that there is a bug in Qt. In this case you should report  the buf with details about your compilers/platform.
>
> But first I would try to change directoryPath to
>
> QString directoryPath = "/foo/bar/baz"; // remove '/' from the end

But note in my test (done with windows-style "\" rather than
unix-style "/") that "/foo/bar/baz/" was interpreted as directory
"/foo/bar/baz/" and no pre-loaded file name, while "/foo/bar/baz"
(no trailing "/") was interpreted as directory "/foo/bar/" and
pre-loaded file name "baz".

K. Frank

> ...
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of yogesh upreti
> Sent: Tuesday, June 08, 2010 4:36 AM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QFileDialog::getOpenFileName Directory name
>
> Hallo Oliver,
> I was aware about the fact that its a static method, so I first wrote the code without an instance. But my problem is this. If I write:
>  QString filePath = QFileDialog::getOpenFileName(this, "Caption", "/foo/bar/baz/", "*.D"); (this is what I mean giving dir path explicitly);
> it opens the dialog box in "/foo/bar/baz/" dir.
> But if I write it
> QString directoryPath = "/foo/bar/baz/";
> QString filePath = QFileDialog::getOpenFileName(this, "Caption", directoryPath, "*.D");
>
> it dosen't open it in "/foo/bar/baz/" instead it opens it in current working dir. I am using Nokia Qt SDK 2010 for compiling my programme.
>
> I will try in the way you said (example with fd.exec()) and give the feedback.
>
> Thanks
> Yogesh
> ...

_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”




More information about the Qt-interest-old mailing list