QProcess argument format?



  • Just a reality check.:

    I am playing around with this awesome C++ program to generate audio waveforms audiowaveform and calling it from Qt using QProcess.

    I need to provide a range of arguments to the program. For example:

    -i test.mp3 -o test.dat -z 256 -b 8
    -i test.dat -o test.png --pixels-per-second 50 -s 5.0 -w 1000 -h 200

    I only got it to work when I broke up each params like this:

    QStringList arguments;
    arguments << "-i" << "/Users/Desire/test.mp3" << "-o" << "/Users/Desire/test.dat" << "-z" << "256" << "-b" << "8";
    

    I'm curious why the following doesn't work (providing one string):

    QStringList arguments << "-i  /Users/Desire/test.dat -o /Users/Desire/test.png --pixels-per-second 50 -s 5.0 -w 1000 -h 200";
    

    Here's the full working method – writes a .dat file and a .png to the path provided: (QProcess instance defined elsewhere)

    void MainWindow::runProcess()
    {
        qDebug() << "run process";
        QString program = "/usr/local/bin/audiowaveform";
        QStringList arguments;
        arguments << "-i" << "/Users/Desire/test.mp3" << "-o" << "/Users/Desire/test.dat" << "-z" << "256" << "-b" << "8";
    
        process->start(program, arguments);
        process->waitForFinished();
        qDebug() <<  process->errorString();
    
        arguments.clear();
        arguments << "-i" << "/Users/Desire/test.dat"<< "-o" << "/Users/Desire/test.png" << "--pixels-per-second" << "50" << "-s" << "5.0" << "-w" << "1000" << "-h" << "200";
        process->start(program, arguments);
        process->waitForFinished();
        qDebug() <<  process->errorString();
    }
    

  • Qt Champions 2016

    @TOMATO_QT
    Hello again,
    The reason is because you may want to pass arguments containing spaces, so Qt will not venture to split them for you. If you want to pass multiple arguments, you have to split (build the list) by yourself.
    Here's the relevant part of the QProcess::start's documentation:

    Note: No further splitting of the arguments is performed.

    Kind regards.



  • @kshegunov

    Ok – I see that now. Looks like there are some other options too.

    And, oh wait. . . wait. . .. there is a specific Windows advisory too (per my earlier frustration about platform specific stuff not being mentioned explicitly in the class documentation)

    img

    ;-) thanks again for your help.


  • Qt Champions 2016

    Again, I don't write it, I just use it the best I can. ;) Anyway, I'm glad I was of help.
    Kind regards.


Log in to reply
 

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