QT Open external programs and folders need to pay attention to the details (note qprocess space problems, and open local files, need to Qurl::fromlocalfile to do)

Source: Internet
Author: User

There are a few small details that need to be recorded here in the afternoon writing program.

?
123456789101112131415 QProcess *process = new QProcess(this);    QFileInfo fileinfo(appUrl);    QString appPath = QApplication::applicationDirPath()+SAVEDIR+"/"+fileinfo.fileName();    bool res = process->startDetached(appPath,QStringList());    if (res)    {        accept();    }    else    {        MyHelper::ShowMessageBoxError("下载完成但自动升级失败,请手工安装升级包!");        QDesktopServices::openUrl(QUrl::fromLocalFile(QApplication::applicationDirPath()+SAVEDIR));        reject();    }
    • Detail 1:

This was written in the original code:
process->startDetached(appPath);
There is no problem with the test environment, but the production environment cannot invoke external programs and eventually discovers that the file path of the production environment
C:\Program Files (x86)\...With a space, causing the call to fail, so Google then tries to
process->startDetached(appPath,QStringList());
Problem solved.

    • Detail 2:

QDesktopServices::openUrl(QUrl(QApplication::applicationDirPath()+SAVEDIR));
The same problem exists in this place, and if you use qurl::fromlocalfile for processing, you can open the folder normally:
QDesktopServices::openUrl(QUrl::fromLocalFile(QApplication::applicationDirPath()+SAVEDIR));

In addition, there is a problem with this code-Independent: QT Call VC write dynamic Library, VC need to use C way output function, otherwise MinGW32 compile process will error, namely:
Example VC DLL header file:

?
12345678910111213 #ifndef cdoublereaderdll  #ifdef cdoublereaderdll_exports #define cdoublereaderdll extern "C" __declspec (dllexport) #else #define cdoublereaderdll extern" C "__declspec (dllimport) #endif #endif    # define buffersize # define ReadTimeout //open serial port Cdoublereaderdll bool _stdcall  Rd_open ( int iport,unsigned long ibaudrate); ...

Examples of calls in QT:

?
1234 extern"C"{    #include "drivers/CdoubleReaderDll.h"}

Reprint Please specify: Under the Sycamore Tree»QT open External programs and folders to pay attention to the details

http://www.pfeng.org/archives/808

QT Open external programs and folders need to pay attention to the details (note qprocess space problems, and open local files, need to Qurl::fromlocalfile to do)

Related Article

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.