[Solved] QProcess and backlight linux command



  • Hello Guys!
    I try to modify the brightness of my display in Qt, running the command:

    echo 6 > /sys/class/backlight/mxs-bl/brightness

    and using QProcess like this:

    @QProcess *sh = new QProcess();
    sh->start( "echo 6 > /sys/class/backlight/mxs-bl/brightness");
    sh->waitForFinished();
    QByteArray output = sh->readAll();
    ui->label->setText(output);
    sh->close();@

    But it print only "6 > /sys/class/backlight/mxs-bl/brightness" instead of do the command like in the shell, and don't change the value of the brightness.
    Any idea? Thank you so much.


  • Moderators

    try this:
    @
    QProcess *sh = new QProcess();
    sh->write("6"); //write to stdin of the process
    //sh->closeWriteChannel(); //not sure if this line is needed
    sh->start( "/sys/class/backlight/mxs-bl/brightness");
    @



  • It didn't work, :-( don't change anything


  • Moderators

    ok... one more try:
    @
    QProcess *sh = new QProcess();
    sh->start( "/sys/class/backlight/mxs-bl/brightness");
    sh->write("6"); //write to stdin of the process
    sh->closeWriteChannel();
    @



  • nothing to do, still does not do anything, but excuse me I should not include the echo command? is not recognized ">" sign on Qt



  • Why are you trying to use QProcess to write to file?
    Wouldn't it be easier to use QFile?

    @
    QFile f("/sys/class/backlight/mxs-bl/brightness");
    f.open(QIODevice::WriteOnly | QIODevice::Truncate);
    f.write("6");
    @



  • Thank you it works ;-)


  • Moderators

    well ... i thought "/sys/class/backlight/mxs-bl/brightness" is a application rather than a file.
    I thought you know what your were doing when you using QProcess in the first place ;)


Log in to reply
 

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