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. Adjust screen backlight

Adjust screen backlight

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 526 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
    Jakob Clausen
    wrote on last edited by
    #1

    Hi.
    I am trying to adjust the screen backlight.
    I can do it from the terminal using

    echo 26 > /sys/class/backlight/lvds0_backlight/brightness
    

    Where 26 is maximum brightness.
    But if I try it from the code it does not work.

    qDebug() << startCommand(value);
    QProcess::execute(startCommand(value));
    
    QString Brightness::startCommand(uint8_t value)
    {
        return "echo echo " + QString::number(value) + " > /sys/class/backlight/lvds0_backlight/brightness";
    }
    

    which gives the output:

    "echo echo 26 > /sys/class/backlight/lvds0_backlight/brightness"
    echo 26 > /sys/class/backlight/lvds0_backlight/brightness
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • J Jakob Clausen

      Hi.
      I am trying to adjust the screen backlight.
      I can do it from the terminal using

      echo 26 > /sys/class/backlight/lvds0_backlight/brightness
      

      Where 26 is maximum brightness.
      But if I try it from the code it does not work.

      qDebug() << startCommand(value);
      QProcess::execute(startCommand(value));
      
      QString Brightness::startCommand(uint8_t value)
      {
          return "echo echo " + QString::number(value) + " > /sys/class/backlight/lvds0_backlight/brightness";
      }
      

      which gives the output:

      "echo echo 26 > /sys/class/backlight/lvds0_backlight/brightness"
      echo 26 > /sys/class/backlight/lvds0_backlight/brightness
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Jakob-Clausen said in Adjust screen backlight:

      But if I try it from the code it does not work.

      "echo echo 26 > /sys/class/backlight/lvds0_backlight/brightness"

      What do oyu expect when you double 'echo' ?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @Jakob-Clausen said in Adjust screen backlight:

        But if I try it from the code it does not work.

        "echo echo 26 > /sys/class/backlight/lvds0_backlight/brightness"

        What do oyu expect when you double 'echo' ?

        J Offline
        J Offline
        Jakob Clausen
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        If do it with a single echo, then I get the output

        "echo 12 > /sys/class/backlight/lvds0_backlight/brightness"
        12 > /sys/class/backlight/lvds0_backlight/brightness
        

        and still no effect.

        JonBJ 1 Reply Last reply
        0
        • J Jakob Clausen

          @Christian-Ehrlicher
          If do it with a single echo, then I get the output

          "echo 12 > /sys/class/backlight/lvds0_backlight/brightness"
          12 > /sys/class/backlight/lvds0_backlight/brightness
          

          and still no effect.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Jakob-Clausen
          Whether you are Linux or Windows in both cases it is only a shell which interprets a redirection symbol like >. You cannot execute this line as the program argument to QProcess::execute(). If you are Linux try

          QProcess::execute("/bin/sh", QStringList() << "-c" << "echo " + QString::number(value) + " > /sys/class/backlight/lvds0_backlight/brightness");
          

          Having said that, this is not a good way to implement it. There is no point firing a command to call "echo" to send "26" to a path. Just open that device path for write and send it the number, no QProcess needed.

          1 Reply Last reply
          3
          • J Offline
            J Offline
            Jakob Clausen
            wrote on last edited by
            #5

            It works.
            The commandline suggestion worked.
            And the better idea also worked.

            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