Open file in QT with default program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.