Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to pass a character to Qprocess.
QtWS25 Last Chance

How to pass a character to Qprocess.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jaswinder
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tzander
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jaswinder
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tzander
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved