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 add a button that runs a command line in Raspbian terminal ?
Forum Updated to NodeBB v4.3 + New Features

How to add a button that runs a command line in Raspbian terminal ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 404 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.
  • I Offline
    I Offline
    imene
    wrote on 18 Aug 2022, 06:58 last edited by
    #1

    Hello,
    i want to run this line in raspbian Terminal to activate PiCAN raspberry pi module:

    pi@raspberrypi:~ $ sudo /sbin/ip link set can0 up type can bitrate 1000000 loopback on
    

    How can i do it ?
    Qt5-12

    J 1 Reply Last reply 18 Aug 2022, 08:03
    0
    • I imene
      18 Aug 2022, 06:58

      Hello,
      i want to run this line in raspbian Terminal to activate PiCAN raspberry pi module:

      pi@raspberrypi:~ $ sudo /sbin/ip link set can0 up type can bitrate 1000000 loopback on
      

      How can i do it ?
      Qt5-12

      J Offline
      J Offline
      JonB
      wrote on 18 Aug 2022, 08:03 last edited by
      #2

      @imene
      Use QProcess.

      1 Reply Last reply
      1
      • I Offline
        I Offline
        imene
        wrote on 18 Aug 2022, 08:14 last edited by
        #3

        I've tried this code but he didn't found the command:
        from(https://forum.qt.io/topic/113592/run-command-line-from-qt-app-in-linux/6)
        void ConnectDialog::on_Connect_Button_clicked()
        {
        using namespace std;
        qDebug()<<"checking the use of ls in qt * \n";
        QProcess process;
        process.setWorkingDirectory("/home/pi");

        QString Command;    //Contains the command to be executed
        QStringList args;   //Contains arguments of the command
        
        Command = "sudo";
        args<<"/sbin/ip link set can0 up type can bitrate 1000000 loopback on"<<"/home/pi";
        qDebug()<<"Home cmd"<<Command;
        qDebug()<<"Home args"<<args;
        process.start(Command, args, QIODevice::ReadOnly); //Starts execution of command
        
        process.waitForFinished();
        QString StdOut = process.readAllStandardOutput(); //Reads standard output
        qDebug()<<"\n Printing the standard output..........\n";
        // invalid //
        qDebug()<<StdOut;
        
        //cout<<"\n Printing the standard error..........\n";
        QString StdError    =   process.readAllStandardError();   //Reads standard error
        qDebug()<<StdError;
        

        }

        e49e0ddb-a29b-484d-9ed3-df8ccc2003eb-image.png

        J 1 Reply Last reply 18 Aug 2022, 08:18
        0
        • I imene
          18 Aug 2022, 08:14

          I've tried this code but he didn't found the command:
          from(https://forum.qt.io/topic/113592/run-command-line-from-qt-app-in-linux/6)
          void ConnectDialog::on_Connect_Button_clicked()
          {
          using namespace std;
          qDebug()<<"checking the use of ls in qt * \n";
          QProcess process;
          process.setWorkingDirectory("/home/pi");

          QString Command;    //Contains the command to be executed
          QStringList args;   //Contains arguments of the command
          
          Command = "sudo";
          args<<"/sbin/ip link set can0 up type can bitrate 1000000 loopback on"<<"/home/pi";
          qDebug()<<"Home cmd"<<Command;
          qDebug()<<"Home args"<<args;
          process.start(Command, args, QIODevice::ReadOnly); //Starts execution of command
          
          process.waitForFinished();
          QString StdOut = process.readAllStandardOutput(); //Reads standard output
          qDebug()<<"\n Printing the standard output..........\n";
          // invalid //
          qDebug()<<StdOut;
          
          //cout<<"\n Printing the standard error..........\n";
          QString StdError    =   process.readAllStandardError();   //Reads standard error
          qDebug()<<StdError;
          

          }

          e49e0ddb-a29b-484d-9ed3-df8ccc2003eb-image.png

          J Offline
          J Offline
          JonB
          wrote on 18 Aug 2022, 08:18 last edited by
          #4

          @imene said in How to add a button that runs a command line in Raspbian terminal ?:

          args<<"/sbin/ip link set can0 up type can bitrate 1000000 loopback on"<<"/home/pi";

          This is quite wrong. In no way is /sbin/ip link set can0 up type can bitrate 1000000 loopback on a single argument!

          Either

          • Every one of those space-separated words is a separate argument, like args << "/sbin/ip" << "link" << "set" << ....; or
          • Use /bin/sh as the command and args << "-c" << "sudo /sbin/ip link set can0 up type can bitrate 1000000 loopback on".
          1 Reply Last reply
          3
          • I Offline
            I Offline
            imene
            wrote on 18 Aug 2022, 09:10 last edited by imene
            #5

            @JonB Great it works now !

                Command = "sudo";
                args << "/sbin/ip" << "link" << "set" << "can0" << "up" << "type" << "can" << "bitrate" << "1000000" << "loopback" <<"on";
            

            Thanks a lot !

            1 Reply Last reply
            0

            1/5

            18 Aug 2022, 06:58

            • Login

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