PDA

View Full Version : QProcess?



nthung
30th September 2011, 10:43
Hi all
i don't know why this code does not run. I want to open C:\PDF_Solution.doc file. But it seems that nothing happend
pls help me
thanks


#include <QtCore/QCoreApplication>
#include<QProcess>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QProcess Pr;
Pr.start("C:\PDF_Solution.doc",QIODevice::ReadOnly);
Pr.waitForFinished(300);
return a.exec();
}

llev
30th September 2011, 13:32
I guess it should be "C:\\PDF_Solution.doc" instead of "C:\PDF_Solution.doc".
If it was a typo and corrected code doesn't work anyway then try the following:


QDesktopServices::openUrl( QUrl::fromLocalFile( QDir::fromNativeSeparators( "C:\\PDF_Solution.doc" ) ) );

nthung
1st October 2011, 03:20
thanks very much, your way is run well
but, I wonder that why way can't run?
thanks

ChrisW67
1st October 2011, 05:57
"C:\\PDF_Solution.doc" is not a Windows executable file. The Windows API CreateProcess (http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx) call that Qt ultimately uses expects an executable. The file type association magic you are expecting to happen is managed by the Windows shell (and by extension by QDesktopServices).