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. Qt pushButton trigger terminal command
Forum Updated to NodeBB v4.3 + New Features

Qt pushButton trigger terminal command

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 1.8k 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.
  • F Offline
    F Offline
    frodi
    wrote on last edited by
    #1

    Hi. I am totally new to Qt.
    Is there any way that a Qt pushButton can trigger a terminal command? f.ex netcat?

    JonBJ 1 Reply Last reply
    0
    • F frodi

      Hi. I am totally new to Qt.
      Is there any way that a Qt pushButton can trigger a terminal command? f.ex netcat?

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

      @frodi
      What is a "terminal command"? I see a Linux netcat program. Does it keep running after you start it? Does it write stdout?

      I assume you mean you want to use QProcess to run a command. The detail of having that invoked when a QPushButton is clicked is neither here nor there. You have to decide where you want its output to show, e.g. in an xterm or read in & displayed by your calling program, etc.

      1 Reply Last reply
      3
      • F Offline
        F Offline
        frodi
        wrote on last edited by
        #3

        Well, I am thinking of a scenario where i click a button an then a netcat command is executed in the linux terminal

        JonBJ jsulmJ 2 Replies Last reply
        0
        • F frodi

          Well, I am thinking of a scenario where i click a button an then a netcat command is executed in the linux terminal

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

          @frodi
          In what Linux terminal?

          Yours is a GUI application which has button, right? So there is no terminal. You have to create one to run the command in, which is why I mentioned xterm. If that is what you need.

          I answered a question like this months ago. Have a look at https://forum.qt.io/topic/93735/start-terminal-with-command-by-qprocess/17, where I tracked down xterm -e <program> <argument> <argument> as the QProcess command-line. Is that what you want?

          1 Reply Last reply
          3
          • F frodi

            Well, I am thinking of a scenario where i click a button an then a netcat command is executed in the linux terminal

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @frodi You don't need a terminal to run executables (unless you really want to see a terminal for some reason).
            Simply use QProcess to execute the executables.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            F 1 Reply Last reply
            1
            • jsulmJ jsulm

              @frodi You don't need a terminal to run executables (unless you really want to see a terminal for some reason).
              Simply use QProcess to execute the executables.

              F Offline
              F Offline
              frodi
              wrote on last edited by
              #6

              @jsulm I dont need to see the terminal. I just need to send a command via netcat. As I am totally new to this topic, could you give me an example of how i can use the command:

              echo '3b00010000001b010001000000120000013000002713000300030101' | xxd -r -p | nc 172.16.4.44 30013
              

              With the use of a QProcess?

              jsulmJ 1 Reply Last reply
              0
              • F frodi

                @jsulm I dont need to see the terminal. I just need to send a command via netcat. As I am totally new to this topic, could you give me an example of how i can use the command:

                echo '3b00010000001b010001000000120000013000002713000300030101' | xxd -r -p | nc 172.16.4.44 30013
                

                With the use of a QProcess?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @frodi http://doc.qt.io/qt-5/qprocess.html

                QString program = "sh";
                QStringList arguments;
                arguments << "-c" << "echo" << "'3b00010000001b010001000000120000013000002713000300030101'" << "|" << "xxd" << "-r" << "-p" << "|" << "nc" << "172.16.4.44 30013";
                
                QProcess myProcess;
                myProcess.start(program, arguments);
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                JonBJ 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @frodi http://doc.qt.io/qt-5/qprocess.html

                  QString program = "sh";
                  QStringList arguments;
                  arguments << "-c" << "echo" << "'3b00010000001b010001000000120000013000002713000300030101'" << "|" << "xxd" << "-r" << "-p" << "|" << "nc" << "172.16.4.44 30013";
                  
                  QProcess myProcess;
                  myProcess.start(program, arguments);
                  
                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @jsulm
                  Although I admit I have not tried it, this does not look right. The syntax of /bin/sh (or /bin/bash) for a command is:

                  /bin/sh -c "single-argument-to--c-argument"
                  

                  You are passing each bit as a separate argument to bin/sh -c, which will surely go wrong at least depending on what is in the arguments (whitespace, quotes, pipe symbols, ...)...?

                  I would have expected something more like:

                  QString program = "/bin/sh";
                  QStringList arguments;
                  arguments << "-c" << "echo '3b00010000001b010001000000120000013000002713000300030101' | xxd -r -p | nc 172.16.4.44 30013"
                  
                  1 Reply Last reply
                  1

                  • Login

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