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)

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
  • 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.
  • H Offline
    H Offline
    houmingc
    wrote on 27 Jan 2015, 08:29 last edited by
    #10

    Seeking help again. My Ubuntu terminal does open, but nothing is wrote onto it. why is it so?

    @
    QProcess *myProcess = new QProcess;
    myProcess->start("gnome-terminal");
    myProcess->waitForStarted(5000);
    myProcess->write("Qt rocks");
    myProcess->write("sudo -S ifconfig eth0 192.168.100.4 netmask 255.255.255.0");

    @

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

      Seeking help again. My Ubuntu terminal does open, but nothing is wrote onto it. why is it so?

      @
      QProcess *myProcess = new QProcess;
      myProcess->start("gnome-terminal");
      myProcess->waitForStarted(5000);
      myProcess->write("Qt rocks");
      myProcess->write("sudo -S ifconfig eth0 192.168.100.4 netmask 255.255.255.0");

      @

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

        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
        • 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

                                          19/32

                                          27 Jan 2015, 09:30

                                          • Login

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