PDA

View Full Version : QProcess - Failed to start



sankar
18th March 2011, 02:46
Hi,

From my QT application, tried to launch a text file using the following code,

QProcess *myProcess = new QProcess(this);
myProcess->start("E:\\temp1.txt", QStringList() << " ", QIODevice::ReadOnly);

But it says "Failed to start" during execution. Could some one help me to fix this error.

FYI: Went through all threads, but couldn't find the reason for the above problem.

Regards,
Sankar.

schnitzel
18th March 2011, 04:19
I have never played with QProcess, but looking at the method signature, the first argument to the start method is the *program* and the second argument would be the arguments in the form of a QStringList *to* the program.

sankar
18th March 2011, 05:35
Yes, I agree schnitzel. May be i should give "notepad" application path in first argument i think. But how do we then launch a text file?

Could you tell me how to launch a text file in read mode from my Qt App.

Regards,
Sankar.

schnitzel
18th March 2011, 06:08
Can you please explain what you want to achieve?
I don't understand 'launch a text file'.

Launch the text file in *what*?

ChrisW67
18th March 2011, 06:14
Here are some options:

You could provide "notepad.exe" as the program and the full path to the text file in the QStringList of arguments.
You could use "cmd.exe" as the program and two arguments "/C" and the full path to the file. The lets the shell worry about what application to launch for the provided file.
You could use the Windows registry to determine the associated program and launch it.
You could have your program allow the user to specify what to open text files with.
You could show the file (it is text after all) in a Qt widget and not depend on an external program at all.

sankar
18th March 2011, 06:29
Thanks a lot again Chris.

Regards,
Sankar.

Rhayader
18th March 2011, 21:00
And another option is the QDesktopServices::openUrl

ChrisW67
19th March 2011, 08:18
Nice one Rhayader. I've actually used that myself but it completely slipped my mind. This option has the benefit of not being platform specific.

sankar
21st March 2011, 05:57
Thanks Rhayader. It worked as expected.

I modified my code to make use of this, since this is platform independent.

Regards,
Sankar.