PDA

View Full Version : Problem with file paths in XP



IndikaU
13th October 2011, 09:26
Hi,

I'm using QFileDialog to get file paths in my program. These paths are valid in Windows 7. But when I use the same code for Windows XP, there is an error interpreting the file paths correctly (specified file not found). This happen when there are spaces in the path (e.g.: C:\Documents and Settings\...)

How can overcome this problem?

Thanks,
Indika...

nish
13th October 2011, 09:50
Can you show some code as to how are you using the path returned from QFileDialog?

IndikaU
13th October 2011, 09:53
_OutputFolder = QFileDialog::getExistingDirectory(0, ("Select Output Folder"), QDir::currentPath());

nish
13th October 2011, 10:58
i asked, how are you using _OutputFolder later in your code where the error comes.

IndikaU
13th October 2011, 11:35
QStringList args;
args << _OutputFolder;

process = new QProcess(this);
process2 = new QProcess(this);

process->start("./Generator.exe", args); //this works fine
process2->start("explorer.exe", args); //this won't open the destination folder in XP since it can't identify the path (probably with spaces)

nish
13th October 2011, 11:47
add "(quotes) to your file path.


_OutputFolder = "\"" + _OutputFolder + "\"";

EDIT:
But it should have worked without quotes, because in QProcess docs its written that the quotes are automatically added. Does explorer.exe opens?

IndikaU
13th October 2011, 12:58
No it does not open the explorer. See the screenshot below with the code I gave you.
6977

I found that all '\' is printed as '/' in the error message.

Added after 1 2 minutes:

How to get this done? please help.

wysota
13th October 2011, 15:53
QFileDialog returns a path which is correct to use within Qt. It can't guarantee that if you use it directly in a call to an external application, the application will be able to handle it. If you just want to use explorer on the path provided then use QDesktopServices::openUrl() passing in the result of QUrl::fromLocalFile(). In a general situation you'd need to prepare the path manually so that the external app understands it (it is supprising though that explorer can't handle forward-slashed file paths, I thought XP handled that ok).

Michael Druckenmiller Sr
13th October 2011, 16:33
The question I'd have is what is QFileDialog actually returning under each of the OS'...

In Python I would edit in Idle and "print" the value in question.

In VB-6 I'd use Debug.Print and have the Debug window up.

If all else fails print it to your Window Title. :)

So far, knock... knock... knock... I have not had a file path issue between WinXP and Win7 using VB-6. But, VB-6 "baby's" the programmer.

A problem does exist when using C:\Program Files\Some.exe from a command window, in this case XP requires the entire pathname to be in quotes.

If your language is passing this, using some form of a command mode, then XP will only see the pathname to the first space.

You could even experiment by creating a test Folder/Directory (in both OS') that has no spaces in it and see if it works.

If it does, then that "probably" indicates, that, for whatever reason, XP isn't seeing the whole pathname because of embedded spaces.

My only hope in rambling so, it that it sparks a useful thought from those that *really* know what they are doing.

Mike Sr.

As I said, my first step would be to see what is actually being returned in each OS and then, if need be use a switch to modify the value based on which OS you are in.

DOES ANYONE KNOW HOW TO KEEP THESE ENTRY AREAS FROM AUTO-SCROLLING BACK TO THE TOP????

wysota
13th October 2011, 19:40
In Qt there is qDebug() you can use for debugging.

By the way, I don't experience any auto-scrolling :)

Michael Druckenmiller Sr
13th October 2011, 19:44
I am on a Locked down work machine that is still using IE7...

It may be an IE issue because IE9 at home does the same thing...

Seems to happen during Auto Save, and periods of inactivity.

What browser are you using?

Mike Sr.

wysota
13th October 2011, 19:56
We're getting offtopic here. If you want to discuss functionality of the site, please post in the Feedback forum (when you're allowed to).

IndikaU
14th October 2011, 08:04
Hi,

With all comments I think that the actual problem was Windows XP explorer would not handle paths with '/'. So this may be problem when coding for both XP and 7.

How to detect the OS to replace '/' with '\'?

Note: Same code works fine with Windows 7 since it can handle '/';

Indika...

nish
14th October 2011, 09:12
QDir::toNativeSeparators