How to pass a character to Qprocess.



  • Hello all,
    I am using a commandline tool (ffmpeg) to convert media formats. This is working perfect. Now i want to pass a 'q' to command line tool to stop its working on cancel click.
    (command line tool says press 'q' to stop)
    i can stop this if i run this tool in cmd in windows by pressing 'q' Key from the keyboard. I want the same working in Qt when i press cancel button. i already have a slot of cancel click button.
    This is my code.
    class.h

    @
    QProcess proc ;
    bool stop();
    @

    class.cpp

    @ QString codecTool;
    codecTool = "ffmpeg/ffmpeg";
    #ifdef Q_OS_WIN
    codecTool="ffmpeg/win64/ffmpeg";
    #endif
    #ifdef Q_OS_WIN32
    codecTool="ffmpeg/win32/ffmpeg";
    #endif
    QStringList arguments;
    //Overwrite file
    arguments.append("-y");
    //get Info
    arguments.append("-i");
    arguments.append(sourcefilePath);
    //Set Codec
    arguments.append("-acodec");
    arguments.append(setCodec);
    //Set Bitrate
    arguments.append("-ab");
    arguments.append(setBitrate+"k");
    //Set Samplerate
    arguments.append("-ar");
    arguments.append(setSamplerate);
    arguments.append(targetfilePath+"."+extension);
    proc.setProcessChannelMode(QProcess::MergedChannels);
    int check=proc.execute(codecTool, arguments);@

    @bool ffmpeghandler::stop()
    {
    qDebug()<<"qprocess"<<proc.pid();
    proc.write("q");
    proc.write("\n\r");
    }
    @

    when i click on button it print process id but unable to stop.
    Any one have any idea.
    Thanks in advance.



  • can you try to add an additional proc.flush() just after those 'write' calls?



  • i tried this but i got an error that flush() is not a member of the qprocess class.
    Something more about this.



  • hmm, yeah, its not a steam, my bad.

    Anotyher idea would be to make sure you read all the input. If you don't read it, the output may end up being queued forever.


Log in to reply
 

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