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. How to write code that enters lines in the Command Arguments Section
Forum Updated to NodeBB v4.3 + New Features

How to write code that enters lines in the Command Arguments Section

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 5 Posters 4.9k 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.
  • L Offline
    L Offline
    lolilol78
    wrote on 23 Jul 2018, 16:21 last edited by
    #1

    Hello everybody,

    I want my code to be able to make a connection with Arduino simply by running it.

    com : Com5 and baud : 9600

    It is in a text file as first lines

    I would like to know if there is a code that can actually take those lines and put them inside "command line arguments" in the Run section?

    Thanks for your help guys

    1 Reply Last reply
    1
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 23 Jul 2018, 16:52 last edited by mrjj
      #2

      Hi
      Do you mean something in creator that would take a text file and put first line here
      alt text

      I have never seen that.
      Also normally the app itself could read the text file for default
      parameters.

      L 1 Reply Last reply 23 Jul 2018, 17:00
      3
      • M mrjj
        23 Jul 2018, 16:52

        Hi
        Do you mean something in creator that would take a text file and put first line here
        alt text

        I have never seen that.
        Also normally the app itself could read the text file for default
        parameters.

        L Offline
        L Offline
        lolilol78
        wrote on 23 Jul 2018, 17:00 last edited by
        #3

        @mrjj Hello :)

        Exactly this !

        Dont know if this is possible..

        M 1 Reply Last reply 23 Jul 2018, 17:02
        0
        • L lolilol78
          23 Jul 2018, 17:00

          @mrjj Hello :)

          Exactly this !

          Dont know if this is possible..

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 23 Jul 2018, 17:02 last edited by mrjj
          #4

          @lolilol78
          hi
          Not really. its stored in the project.pro.user file so while its possible to
          change it from outside, but Creator will ignore it if already open.

          Why dont u just make app use those as default ?
          so if no parameters use, the defaults.
          or make it read the text file.

          Im not sure i understand why u simply cant just put in Creator directly then ?

          L 1 Reply Last reply 23 Jul 2018, 17:06
          1
          • L Offline
            L Offline
            lolilol78
            wrote on 23 Jul 2018, 17:04 last edited by
            #5

            That would take 2 lines of my text file , and insert them one by one there

            1 Reply Last reply
            0
            • M mrjj
              23 Jul 2018, 17:02

              @lolilol78
              hi
              Not really. its stored in the project.pro.user file so while its possible to
              change it from outside, but Creator will ignore it if already open.

              Why dont u just make app use those as default ?
              so if no parameters use, the defaults.
              or make it read the text file.

              Im not sure i understand why u simply cant just put in Creator directly then ?

              L Offline
              L Offline
              lolilol78
              wrote on 23 Jul 2018, 17:06 last edited by
              #6

              @mrjj

              I will check but that is my tutor who told me to do something like this..

              M 1 Reply Last reply 23 Jul 2018, 17:07
              0
              • L lolilol78
                23 Jul 2018, 17:06

                @mrjj

                I will check but that is my tutor who told me to do something like this..

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 23 Jul 2018, 17:07 last edited by
                #7

                @lolilol78
                but are u sure he didnt mean that APP should read text file ?
                and not Creator ?

                L 1 Reply Last reply 23 Jul 2018, 17:34
                0
                • M mrjj
                  23 Jul 2018, 17:07

                  @lolilol78
                  but are u sure he didnt mean that APP should read text file ?
                  and not Creator ?

                  L Offline
                  L Offline
                  lolilol78
                  wrote on 23 Jul 2018, 17:34 last edited by
                  #8

                  @mrjj
                  I created a code in exe that reads the text file and sort it

                  but then how can i do the connection com5 and baudrate 9600 if not typed manually inside the edit tab

                  M 1 Reply Last reply 23 Jul 2018, 18:16
                  0
                  • L lolilol78
                    23 Jul 2018, 17:34

                    @mrjj
                    I created a code in exe that reads the text file and sort it

                    but then how can i do the connection com5 and baudrate 9600 if not typed manually inside the edit tab

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 23 Jul 2018, 18:16 last edited by
                    #9

                    @lolilol78
                    hi
                    well
                    int main(int argc, char *argv[])
                    argc is tells the number of parameters to exe
                    so u can check that if any is given.

                    L 1 Reply Last reply 23 Jul 2018, 18:19
                    0
                    • M mrjj
                      23 Jul 2018, 18:16

                      @lolilol78
                      hi
                      well
                      int main(int argc, char *argv[])
                      argc is tells the number of parameters to exe
                      so u can check that if any is given.

                      L Offline
                      L Offline
                      lolilol78
                      wrote on 23 Jul 2018, 18:19 last edited by
                      #10

                      @mrjj not sure i understood really well, do you have any example please ?

                      M 1 Reply Last reply 23 Jul 2018, 18:27
                      0
                      • L lolilol78
                        23 Jul 2018, 18:19

                        @mrjj not sure i understood really well, do you have any example please ?

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 23 Jul 2018, 18:27 last edited by
                        #11

                        @lolilol78
                        hi
                        there is not much to it.
                        int argc tells the number of arguments.
                        often there is one. which is the path to exe.
                        so if argc is > 1 then there is (extra) parameters which are in the list
                        argv
                        argv is a char * array.

                        #include <QDebug>
                        int main(int argc, char* argv[]) {
                          qDebug() << argv[0];
                          if (argc == 1 ) {
                            qDebug() << "no params given";
                          }
                        
                          QApplication a(argc, argv);
                          MainWindow w;
                          w.show();
                        
                          return a.exec();
                        }
                        
                        
                        L 1 Reply Last reply 23 Jul 2018, 18:34
                        0
                        • M mrjj
                          23 Jul 2018, 18:27

                          @lolilol78
                          hi
                          there is not much to it.
                          int argc tells the number of arguments.
                          often there is one. which is the path to exe.
                          so if argc is > 1 then there is (extra) parameters which are in the list
                          argv
                          argv is a char * array.

                          #include <QDebug>
                          int main(int argc, char* argv[]) {
                            qDebug() << argv[0];
                            if (argc == 1 ) {
                              qDebug() << "no params given";
                            }
                          
                            QApplication a(argc, argv);
                            MainWindow w;
                            w.show();
                          
                            return a.exec();
                          }
                          
                          
                          L Offline
                          L Offline
                          lolilol78
                          wrote on 23 Jul 2018, 18:34 last edited by
                          #12

                          @mrjj ok thanks for your time ,
                          i will try to test something.

                          M 1 Reply Last reply 23 Jul 2018, 18:38
                          0
                          • L lolilol78
                            23 Jul 2018, 18:34

                            @mrjj ok thanks for your time ,
                            i will try to test something.

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 23 Jul 2018, 18:38 last edited by
                            #13

                            @lolilol78
                            hi
                            i would try

                              for (int pcount = 0; pcount < argc; ++pcount) {
                                qDebug() <<  argv[pcount];
                              }
                            
                            

                            with and without parameters in "run"/Creator

                            else just ask.

                            L 1 Reply Last reply 23 Jul 2018, 18:42
                            0
                            • M mrjj
                              23 Jul 2018, 18:38

                              @lolilol78
                              hi
                              i would try

                                for (int pcount = 0; pcount < argc; ++pcount) {
                                  qDebug() <<  argv[pcount];
                                }
                              
                              

                              with and without parameters in "run"/Creator

                              else just ask.

                              L Offline
                              L Offline
                              lolilol78
                              wrote on 23 Jul 2018, 18:42 last edited by
                              #14

                              @mrjj thanks for the line but i didnt really understand what that means ? it is gonna print something ?

                              M 1 Reply Last reply 23 Jul 2018, 18:44
                              0
                              • L lolilol78
                                23 Jul 2018, 18:42

                                @mrjj thanks for the line but i didnt really understand what that means ? it is gonna print something ?

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 23 Jul 2018, 18:44 last edited by
                                #15

                                @lolilol78
                                yes, it will show all parameters u give in creator / on command line when run
                                it was just for u to get a feeling on how it works.

                                L 1 Reply Last reply 23 Jul 2018, 18:48
                                0
                                • M mrjj
                                  23 Jul 2018, 18:44

                                  @lolilol78
                                  yes, it will show all parameters u give in creator / on command line when run
                                  it was just for u to get a feeling on how it works.

                                  L Offline
                                  L Offline
                                  lolilol78
                                  wrote on 23 Jul 2018, 18:48 last edited by
                                  #16

                                  @mrjj oh okay i understand thank you,

                                  but actually the parameters are stock in my text file and i need some code to go get them parameters and make the serial connection between the console and the arduino.

                                  then i dont know if it is possible..

                                  M 1 Reply Last reply 23 Jul 2018, 18:58
                                  0
                                  • L lolilol78
                                    23 Jul 2018, 18:48

                                    @mrjj oh okay i understand thank you,

                                    but actually the parameters are stock in my text file and i need some code to go get them parameters and make the serial connection between the console and the arduino.

                                    then i dont know if it is possible..

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 23 Jul 2018, 18:58 last edited by
                                    #17

                                    @lolilol78

                                    well if if app sees that it got no parameter it could open the text file if u place it next to exe
                                    yes it very possible.
                                    You can use QFile

                                    QFile file("comm.txt");
                                    if(!file.open(QIODevice::ReadOnly)) {
                                        QMessageBox::information(0, "error", file.errorString());
                                    }
                                    
                                    QTextStream in(&file);
                                    
                                    while(!in.atEnd()) {
                                        QString line = in.readLine();    // read first line
                                       qDebug() << line; // here u should set com port/ baud instead.
                                    }
                                    
                                    file.close();
                                    
                                    L 1 Reply Last reply 24 Jul 2018, 13:30
                                    0
                                    • M mrjj
                                      23 Jul 2018, 18:58

                                      @lolilol78

                                      well if if app sees that it got no parameter it could open the text file if u place it next to exe
                                      yes it very possible.
                                      You can use QFile

                                      QFile file("comm.txt");
                                      if(!file.open(QIODevice::ReadOnly)) {
                                          QMessageBox::information(0, "error", file.errorString());
                                      }
                                      
                                      QTextStream in(&file);
                                      
                                      while(!in.atEnd()) {
                                          QString line = in.readLine();    // read first line
                                         qDebug() << line; // here u should set com port/ baud instead.
                                      }
                                      
                                      file.close();
                                      
                                      L Offline
                                      L Offline
                                      lolilol78
                                      wrote on 24 Jul 2018, 13:30 last edited by
                                      #18

                                      @mrjj Thank you mrjj

                                      M 1 Reply Last reply 24 Jul 2018, 13:32
                                      0
                                      • L lolilol78
                                        24 Jul 2018, 13:30

                                        @mrjj Thank you mrjj

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 24 Jul 2018, 13:32 last edited by
                                        #19

                                        @lolilol78
                                        so tutor said ok to read from file?
                                        Note that sample read one line at a time

                                        L 1 Reply Last reply 26 Jul 2018, 17:05
                                        0
                                        • M mrjj
                                          24 Jul 2018, 13:32

                                          @lolilol78
                                          so tutor said ok to read from file?
                                          Note that sample read one line at a time

                                          L Offline
                                          L Offline
                                          lolilol78
                                          wrote on 26 Jul 2018, 17:05 last edited by
                                          #20

                                          @mrjj yes the fils has already been read with another function, but now :
                                          how to actually send those lines one by one to Arduino via Serial Com?

                                          aha_1980A 1 Reply Last reply 26 Jul 2018, 17:18
                                          0

                                          10/28

                                          23 Jul 2018, 18:19

                                          topic:navigator.unread, 18
                                          • Login

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