Usage: Qprocess::execute ("Explorer filename");
Example: Qprocess::execute ("Explorer C:\\123.txt");
----------------------------------------------------------------------
Should have found this method of shrimp early, but I did not search, so there is the following this noisy exploration article.
How to open a file in QT with the default program. For example, given a "123.html" parameter, it can be opened with a browser.
Search the Internet, most of the solution is to use ShellExecute this Windows API function.
feasible, but always hope to find a QT API to use.
Keep looking for information. Discover a qprocess class.
Test Qprocess::execute ("notepad.exe");
Open Notepad successfully.
Thought there was a chance.
Then test------
Qprocess::execute ("Start C:\\123.txt");
Failed. The heart is half cold.
Looking at the Qprocess::execute code, it turns out to be the CreateProcess function that calls Windows.
Start estimation is not a program, it is just a command, so I reported a bug that could not find the program.
Conversely, if you find a program, the program can open the file with the default program.
Keep looking for information.
In a lot of information in the search, finally in a corner to find someone mentioned Explorer.exe.
It's a very familiar name. This is the file Explorer for Windows. Open the Process manager and always see a few running.
The address is as follows (thank the Netizen)
Http://zhidao.baidu.com/link?url=tlp1jLfEsBICWgnTeuKT8hiahA7gFtghzoQ73ufI0frbI5Uw03mI79n5Qi8739oq68nlws4wSRlW0Jmk3wU8Ya
Somewhere, a voice said to me, this is the key to solve the problem. ^-^
Then find the parameter usage of Explorer.exe.
Gossip less said, after a test in CMD. The usage is Explorer filename.
Example: Explorer C:\123.txt
Do not quote arbitrarily, note that with a backslash, in the cmd window only with a bar, or else will open my document.
Test your code in QT
Qprocess::execute ("Explorer C:\\123.txt");
Open successfully! Happy-^
This article is from the "Three people Ride the Tiger" blog, please be sure to keep this source http://darhx.blog.51cto.com/7920146/1641680
Open file in QT with default program