QProcess Arguments List Problem



  • I'm trying to run an external program from Qt using QProcess (Qt Creator IDE, Qt 5.8). I'm developing on Linux Ubuntu 16. The issue I'm having is with the argument list. Below is a snippet of the code:

    QProcess* mProcess;
    QString program;
    QStringList arguments;

    program = "/usr/bin/vlc";
    arguments << " /home/user1/Desktop/small.mp4";
    mProcess = new QProcess();
    if (mProcess != nullptr) {
    mProcess->setProgram(program);
    mProcess->setArguments(arguments);
    mProcess->start();
    mProcess->waitForFinished();
    }

    The vlc program starts but it's unable to find the file: small.mp4. The error I get from vlc is:

    File reading failed:
    VLC could not open the file "/home/user1/Qt/Examples/Qt-5.8/webengine/build-minimal-Desktop_Qt_5_8_0_GCC_64bit-Release/ /home/user1/Desktop/small.mp4" (No such file or directory).

    For some reason the arguments list goes from: /home/user1/Desktop/small.mp4 to /home/user1/Qt/Examples/Qt-5.8/webengine/build-minimal-Desktop_Qt_5_8_0_GCC_64bit-Release/ /home/user1/Desktop/small.mp4

    Anyone know why this happens? Why is it adding the path of the entire project working directory before the arguments list string? it does this no matter which program I try to run. I tried running gedit to open a file on my desktop and it does the same thing. It appended the entire working directory path prior to the path of the location of the text file.

    I tried manually changing the working directory for the project but it is greyed out, Qt Creator does not let me change it.
    I've searched this forum and google for any similar problems but I'm unable to find any.


  • Moderators

    Hi! It's the superfluous space at the beginning of the string " /home/user1/Desktop/small.mp4".



  • Awesome, that did it, thanks!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.