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. Unix command slot creation

Unix command slot creation

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 4.4k 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.
  • P Offline
    P Offline
    potla11
    wrote on 3 Oct 2011, 06:33 last edited by
    #1

    hi.. Is there any way in qt to execute unix commands like "pwd " when a button pressed

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 3 Oct 2011, 07:26 last edited by
      #2

      "QProcess":http://developer.qt.nokia.com/doc/qt-4.7/qprocess.html should be your friend here.

      (Z(:^

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on 3 Oct 2011, 07:50 last edited by
        #3

        "QDir":http://doc.qt.nokia.com/4.7/qdir.html#current might be a better option for your example command. But in general, sierdzio is right.

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fluca1978
          wrote on 3 Oct 2011, 08:22 last edited by
          #4

          I think you should avoid to create such a slot. The beauty of Qt is that the library is platform independent, so if you need to get runtime informations such as the working directory or alike you should use the library services, and not platform specific commands that are going to tie your application to a specific execution environment.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            potla11
            wrote on 3 Oct 2011, 08:49 last edited by
            #5

            my application is not only for path finding..like cp -r sourcefile destinationfile like this type of commands also...

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on 3 Oct 2011, 09:28 last edited by
              #6

              I strongly suggest to avoid running processes like the above directly, or your application will be strictly tied to the unix environment, and maybe to a linux one!
              Use QFile for managing copies, QDir for managing paths and classes alike as much as you can.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 3 Oct 2011, 10:27 last edited by
                #7

                fluca1978, I think you're overreacting a little bit. phani448 seems to have already chosen their way of doing it. It is, of course, possible to use native tools on all platforms by simply specifying different names for tools, depending on the host OS (Qt has a set of OS related #defines that can be used here), and it will work just as well. It might not be the best option in your view (mine too, in fact, at least when it comes to trivial stuff like cp -r or pwd), but the subject here revolves around HOW to run native commands, not WHETHER to use them.

                (Z(:^

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fluca1978
                  wrote on 3 Oct 2011, 10:40 last edited by
                  #8

                  Sorry, I was not saying it is absolutely a bad idea to use QProcess, but that it could be a bad idea for a lot of cases where Qt already provides a wrapping for doing the same task.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    sierdzio
                    Moderators
                    wrote on 3 Oct 2011, 10:42 last edited by
                    #9

                    [quote author="fluca1978" date="1317638423"]Sorry, I was not saying it is absolutely a bad idea to use QProcess, but that it could be a bad idea for a lot of cases where Qt already provides a wrapping for doing the same task. [/quote]

                    And you're perfectly right here :) Cheers.

                    (Z(:^

                    1 Reply Last reply
                    0

                    1/9

                    3 Oct 2011, 06:33

                    • Login

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