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 + command Shell
Forum Updated to NodeBB v4.3 + New Features

Qt + command Shell

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 3.8k 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.
  • G Offline
    G Offline
    gaurav118
    wrote on last edited by
    #1

    Hi all... is there any way around that i can call and read the result of windows shell commands like "date /t" or "time /t" through Qt app

    raven-worxR Gojir4G 2 Replies Last reply
    0
    • G gaurav118

      Hi all... is there any way around that i can call and read the result of windows shell commands like "date /t" or "time /t" through Qt app

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @gaurav118
      read the docs about QProcess

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      6
      • G gaurav118

        Hi all... is there any way around that i can call and read the result of windows shell commands like "date /t" or "time /t" through Qt app

        Gojir4G Offline
        Gojir4G Offline
        Gojir4
        wrote on last edited by Gojir4
        #3

        @gaurav118 Hi,
        For "cmd" command on Windows, you have to put cmd /C in front of your command, otherwise you will see an error (exit code -1 and empty output):

        QString result;
        process.start("cmd /c date /t")
        if(!process.waitForFinished(timeout))
            //Error
        else 
          result = process.readAllStandardOutput()
        

        see this post: https://forum.qt.io/topic/41918/executing-commands-in-cmd-exe-using-qprocess/5

        A better way to handle output is to use signals readyReadStandardOutput() and readyReadStandardError(), using waitForFinished() was simpler for the example.

        G 1 Reply Last reply
        4
        • Gojir4G Gojir4

          @gaurav118 Hi,
          For "cmd" command on Windows, you have to put cmd /C in front of your command, otherwise you will see an error (exit code -1 and empty output):

          QString result;
          process.start("cmd /c date /t")
          if(!process.waitForFinished(timeout))
              //Error
          else 
            result = process.readAllStandardOutput()
          

          see this post: https://forum.qt.io/topic/41918/executing-commands-in-cmd-exe-using-qprocess/5

          A better way to handle output is to use signals readyReadStandardOutput() and readyReadStandardError(), using waitForFinished() was simpler for the example.

          G Offline
          G Offline
          gaurav118
          wrote on last edited by
          #4

          @Gojir4 I am pretty new at Qt. Do we have any sample project doing the same?

          Gojir4G JonBJ 2 Replies Last reply
          0
          • G gaurav118

            @Gojir4 I am pretty new at Qt. Do we have any sample project doing the same?

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by Gojir4
            #5

            @gaurav118 What is the final goal of your application ?

            G 1 Reply Last reply
            1
            • G gaurav118

              @Gojir4 I am pretty new at Qt. Do we have any sample project doing the same?

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

              @gaurav118 said in Qt + command Shell:

              @Gojir4 I am pretty new at Qt. Do we have any sample project doing the same?

              If you are that new: just to check: are you aware that for the examples you give you do not need to run an OS command and parse the output? Qt/C++/whatever will have its own functions for giving you the current date/time.

              G 1 Reply Last reply
              2
              • JonBJ JonB

                @gaurav118 said in Qt + command Shell:

                @Gojir4 I am pretty new at Qt. Do we have any sample project doing the same?

                If you are that new: just to check: are you aware that for the examples you give you do not need to run an OS command and parse the output? Qt/C++/whatever will have its own functions for giving you the current date/time.

                G Offline
                G Offline
                gaurav118
                wrote on last edited by
                #7

                @JonB Yeah i know.. it has QDateTime::currentDateTime.

                1 Reply Last reply
                0
                • Gojir4G Gojir4

                  @gaurav118 What is the final goal of your application ?

                  G Offline
                  G Offline
                  gaurav118
                  wrote on last edited by
                  #8

                  @Gojir4 The idea is to control basic functionality of OS from app itself like IP configuration, Date Time setting, OS reboot, Backend application execution. I just need some sample code on how to use QProcess delicately handling all its exceptions and errors

                  JonBJ 1 Reply Last reply
                  0
                  • G gaurav118

                    @Gojir4 The idea is to control basic functionality of OS from app itself like IP configuration, Date Time setting, OS reboot, Backend application execution. I just need some sample code on how to use QProcess delicately handling all its exceptions and errors

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

                    @gaurav118
                    Yep, then you do need QProcess. For "handling all its exceptions and errors", you will need to read carefully through all its methods/signals/etc., as there are dedicated functions for these.

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gaurav118
                      wrote on last edited by
                      #10

                      Thanx all... I was actually looking for something like this.. Anyhow my issue is resolved now, in case any one need help, simply refer to http://www.informit.com/articles/article.aspx?p=1405549&seqNum=5

                      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