Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to set ip address to a computer in Qt (Solved)
Forum Updated to NodeBB v4.3 + New Features

How to set ip address to a computer in Qt (Solved)

Scheduled Pinned Locked Moved Mobile and Embedded
32 Posts 4 Posters 12.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.
  • P Offline
    P Offline
    p3c0
    Moderators
    wrote on 27 Jan 2015, 08:52 last edited by
    #13

    You need not open a terminal for launching that process. Try following:
    @
    QStringList args;
    args << "-c" << "sudo -S ifconfig eth0 192.168.0.21 < /home/user/passwd.txt";
    pro->start("/bin/sh",args);
    @

    But as said earlier it doesnot provide security as the password file is revealed.
    Another way would be to write a script which will run ifconfig command. Call this script instead of that command. Add an entry for this script in /etc/sudoers alongwith the user that will execute this script (i.e linux user with which you run your application). There are plenty of examples on how to edit sudoers using visudo. Check them out.

    157

    1 Reply Last reply
    0
    • H Offline
      H Offline
      houmingc
      wrote on 27 Jan 2015, 09:26 last edited by
      #14

      i vi a file in /home/ubuntu/passwd.txt with my password. Debug the code. After Application finished running, i do a ifconfig in ubuntu terminal. The ip address has not been changed

      @
      void SetpcAddress{

                             QProcess *myProcess = new QProcess();
                             QStringList args;
                             args<<"-c"<<
        "sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
                              myProcess->start("/bin/sh",args);
      

      }

      int main(void)
      {

                   SetpcAddress();    
      

      }

      @

      1 Reply Last reply
      0
      • H Offline
        H Offline
        houmingc
        wrote on 27 Jan 2015, 09:26 last edited by
        #15

        i vi a file in /home/ubuntu/passwd.txt with my password. Debug the code. After Application finished running, i do a ifconfig in ubuntu terminal. The ip address has not been changed

        @
        void SetpcAddress{

                               QProcess *myProcess = new QProcess();
                               QStringList args;
                               args<<"-c"<<
          "sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
                                myProcess->start("/bin/sh",args);
        

        }

        int main(void)
        {

                     SetpcAddress();    
        

        }

        @

        1 Reply Last reply
        0
        • P Offline
          P Offline
          p3c0
          Moderators
          wrote on 27 Jan 2015, 09:29 last edited by
          #16

          Does that command work from outside ?

          157

          1 Reply Last reply
          0
          • P Offline
            P Offline
            p3c0
            Moderators
            wrote on 27 Jan 2015, 09:29 last edited by
            #17

            Does that command work from outside ?

            157

            1 Reply Last reply
            0
            • H Offline
              H Offline
              houmingc
              wrote on 27 Jan 2015, 09:30 last edited by
              #18

              cat passwd.txt return my password correct

              1 Reply Last reply
              0
              • H Offline
                H Offline
                houmingc
                wrote on 27 Jan 2015, 09:30 last edited by
                #19

                cat passwd.txt return my password correct

                1 Reply Last reply
                0
                • H Offline
                  H Offline
                  houmingc
                  wrote on 27 Jan 2015, 09:34 last edited by
                  #20

                  it works when i do a sudo su
                  it doesn't work without permission, what should i do next?

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    houmingc
                    wrote on 27 Jan 2015, 09:34 last edited by
                    #21

                    it works when i do a sudo su
                    it doesn't work without permission, what should i do next?

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      p3c0
                      Moderators
                      wrote on 27 Jan 2015, 09:40 last edited by
                      #22

                      It does work for me from the App and Outside
                      @
                      args<<"-c"<<
                      "sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
                      @

                      There should be a space before and after < in above command.

                      157

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        p3c0
                        Moderators
                        wrote on 27 Jan 2015, 09:40 last edited by
                        #23

                        It does work for me from the App and Outside
                        @
                        args<<"-c"<<
                        "sudo -S ifconfig eth0 192.168.100.21</home/ubuntu/passwd.txt";
                        @

                        There should be a space before and after < in above command.

                        157

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          houmingc
                          wrote on 27 Jan 2015, 09:41 last edited by
                          #24

                          under /opt
                          cat >password.txt 'Key in my password'
                          cat password 'Check my password'

                          its work, thanks alot :>>

                          1 Reply Last reply
                          0
                          • H Offline
                            H Offline
                            houmingc
                            wrote on 27 Jan 2015, 09:41 last edited by
                            #25

                            under /opt
                            cat >password.txt 'Key in my password'
                            cat password 'Check my password'

                            its work, thanks alot :>>

                            1 Reply Last reply
                            0
                            • P Offline
                              P Offline
                              p3c0
                              Moderators
                              wrote on 27 Jan 2015, 09:52 last edited by
                              #26

                              Well then get the errors using readyReadStandardError() signal if any.

                              157

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                p3c0
                                Moderators
                                wrote on 27 Jan 2015, 09:52 last edited by
                                #27

                                Well then get the errors using readyReadStandardError() signal if any.

                                157

                                1 Reply Last reply
                                0
                                • H Offline
                                  H Offline
                                  houmingc
                                  wrote on 27 Jan 2015, 10:01 last edited by
                                  #28

                                  what does "-c" in front of "sudo -s" meant or used for??

                                  1 Reply Last reply
                                  0
                                  • H Offline
                                    H Offline
                                    houmingc
                                    wrote on 27 Jan 2015, 10:01 last edited by
                                    #29

                                    what does "-c" in front of "sudo -s" meant or used for??

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      p3c0
                                      Moderators
                                      wrote on 27 Jan 2015, 10:23 last edited by
                                      #30

                                      It is for sh so that it reads commands from argument strings. Check "this":http://manpages.ubuntu.com/manpages/utopic/en/man1/sh.1posix.html man page for more details. I hope your system has sh command.

                                      157

                                      1 Reply Last reply
                                      0
                                      • P Offline
                                        P Offline
                                        p3c0
                                        Moderators
                                        wrote on 27 Jan 2015, 10:23 last edited by
                                        #31

                                        It is for sh so that it reads commands from argument strings. Check "this":http://manpages.ubuntu.com/manpages/utopic/en/man1/sh.1posix.html man page for more details. I hope your system has sh command.

                                        157

                                        1 Reply Last reply
                                        0
                                        • H Offline
                                          H Offline
                                          houmingc
                                          wrote on 9 Jun 2015, 07:03 last edited by houmingc 6 Sept 2015, 07:04
                                          #32

                                          QProcess Class is used to start external programs and to communicate with them.
                                          create a new QProcess and input args to /bin/sh.
                                          Below code has been tested working.
                                          Thanks to p3c0, if not, answer below will not be available :

                                          QProcess *myProcess = new QProcess;
                                          QStringList args;
                                          args<"-c"<<"sudo -S ifconfig eth0 192.168.100.1 < /var/passwd.txt");
                                          myProcess->start("/bin/sh",args);
                                          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