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 + system command
Qt 6.11 is out! See what's new in the release blog

QT + system command

Scheduled Pinned Locked Moved General and Desktop
7 Posts 7 Posters 9.7k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi all,

    I am trying to trigger a command "sudo apt-get install --only-upgrade [mysoftware]" in qt so that the linux will update my software when i click update manually.
    Following is piece of code thats not working :
    void MainWindow:: on_whichos_clicked()
    {
    QMessageBox msgBox;

    msgBox.setWindowTitle("Which OS ?");
    #ifdef Q_OS_LINUX
    QProcess process;

    process.start("sudo apt-get", QStringList() << "install setserial" );
    msgBox.setInformativeText("This is Linux OS :)");__
    

    Above code works if the process is gui based but the apt-get or any other shell based process does not work. I am trying to do same thing on windows and mac for my auto update feature.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      You could make a separate thread and use system() call in that thread

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        Hi, AFAIK, QProcess works for all the cases in mentioned.

        Please note that, if you want to run bash command, the program you started is the bash instead of the bash command. If you run some command such as "sudo apt-get ...", the command is sudo.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          puksec
          wrote on last edited by
          #4

          You can try popen() with write only flag, so you dont have to use another thread (like with system()).

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            @process.start(“sudo apt-get”, QStringList() << “install setserial” ); @

            should read

            @process.start(“sudo", QStringList() << "apt-get” << “install" << "setserial” );@

            There is no command on your system called "sudo apt-get". Commands containing spaces are legal, but tend to be avoided on Linux.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              In addition to what Tobias wrote, you will also need a mean to ask the user for it's password i.g. using the -A option

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NTCYP
                wrote on last edited by
                #7

                Hi,

                I am trying to use QT process as;

                // Create QProcess object
                proc = new QProcess();
                proc->start("ping", QStringList() << "-c 10" << QString(www.google.com));

                And I am gettig error as;

                ping: Invalid number '10'

                Any help please,

                Kind Regards

                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