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 make simple app for run some terminal commands
Forum Updated to NodeBB v4.3 + New Features

How to make simple app for run some terminal commands

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 310 Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Makantidur
    wrote on last edited by Makantidur
    #1

    I want to make a simple application for my practice exam. This application is used to run some linux terminal commands such as lsb_release -a, dpkg -l (textbox), sudo apt update (on my xubuntu), sudo pacman -Syu (on my manjaro), and many more. I've started by creating a C++ based Qt Widget Application project. I've made the UI and now I'm confused, where should I put a command like QProcess process1; process1.start("sudo lsb_release -a");. Whereas QProcess is always said to be an error. For your information, the last time I used C++ was 2 years ago. And I have never had any experience using Python.```

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to the forums
      First you should read the docs.
      https://doc.qt.io/qt-5/qprocess.html

      Please notice that any parameters should be included in the QStringList param and not as part of the string for the app.

        QString program = "./path/to/app.exe";
         QStringList arguments;
         arguments << "-arg1" << "arg2";
        QProcess *myProcess = new QProcess(parent);
         myProcess->start(program, arguments);
      

      so start("sudo lsb_release -a") is not right as "-a" should be on its own.

      Then next is the fact that QProcess is asynchronous so make sure that you dont declare
      QProcess process1 inside a function as it will then be deleted before anything happens.
      So make it a class member.

      Then there is sudo. If it asks for password then it wont work.

      About where to have the process1.start, Well how will app work ?
      User must press something or its it automatic in some way ?

      1 Reply Last reply
      3

      • Login

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