Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. struct and passing array parameters

struct and passing array parameters

Scheduled Pinned Locked Moved Solved C++ Gurus
14 Posts 5 Posters 3.3k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    Hi,

    No, a class is a definition used to create objects AKA "instances".

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • D Offline
      D Offline
      Digitale_GFacchini
      wrote on last edited by
      #5

      @sierdzio said in struct and passing array parameters:

      dichiarative myObject;
      myObject.settingDichiarative(argv);

      ok so, i i want use a classe a need a istance.
      Now i have a problem in parameter why? I have declared :

      char* argv
      

      into in file header and in file cpp where is the class dichiarative and his method

          dichiarative myObject;
          myObject.settingDichiarative(argv);
      

      main.cpp:12:38: error: no matching function for call to 'dichiarative::settingDichiarative(char**&)'
      myObject.settingDichiarative(argv);
      ^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        Digitale_GFacchini
        wrote on last edited by Digitale_GFacchini
        #6

        Ok hai have put:

        myObject.settingDichiarative(*argv);
        

        And so it's ok, but now i have error in method settingDichiarative.

        C:\Generale\OneDrive - ELICAT SRL - 03978700288\Developer\QtApplicazioni\youtube_and_web\EVILEG\SQLiteDbAcccesListModel/dichiarative.cpp:14: undefined reference to `dichiarative::paramingresso::arg_db_name'
        

        This error for every idem of structure declared into .h

        struct paramingresso {
                static QString arg_db_type;
                static QString arg_db_driver;
                static QString arg_db_name;
                static QString arg_db_path;
            };
        

        and the method is :

        void dichiarative::settingDichiarative(char* argomenti)
        {
            dichiarative::paramingresso::arg_db_type = QStringLiteral("%1").arg(argomenti[1]);
            dichiarative::paramingresso::arg_db_driver = QStringLiteral("%1").arg(argomenti[2]);
            dichiarative::paramingresso::arg_db_name = QStringLiteral("%1").arg(argomenti[3]);
            dichiarative::paramingresso::arg_db_path = QStringLiteral("%1").arg(argomenti[4]);
        }
        

        In this monts i have sty but it's too much arguments and every time I try to apply I block myself for errors .. Be patient then when I understand bele the logic I will be able to reciprocate. At least I hope

        VRoninV 1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #7

          This is - again - because you have no object / variable of type "paramingresso". In your "dichiarative" class, add this:

          public:
            paramingresso myStruct;
          

          And now modify your method like so:

          void dichiarative::settingDichiarative(char* argomenti)
          {
              myStruct.arg_db_type = QStringLiteral("%1").arg(argomenti[1]);
              myStruct.arg_db_driver = QStringLiteral("%1").arg(argomenti[2]);
              myStruct.arg_db_name = QStringLiteral("%1").arg(argomenti[3]);
              myStruct.arg_db_path = QStringLiteral("%1").arg(argomenti[4]);
          }
          

          Also, as a side note - it's much easier to extract command line arguments using Qt methods. Check out https://doc.qt.io/qt-5/qcoreapplication.html#arguments or (a bit more advanced) https://doc.qt.io/qt-5/qcommandlineparser.html#details

          (Z(:^

          1 Reply Last reply
          5
          • D Offline
            D Offline
            Digitale_GFacchini
            wrote on last edited by
            #8

            Thanks for reference to extract command line. however I continue as an exercise with reading argv and setting up a structure. Are you telling me to instantiate the structure in the header file? If I understand correctly the result is:

            undefined reference to `DichiarativeGlobali::paramingresso::arg_db_type'
            undefined reference to `DichiarativeGlobali::paramingresso::arg_db_driver'
            undefined reference to `DichiarativeGlobali::paramingresso::arg_db_name'
            undefined reference to `DichiarativeGlobali::paramingresso::arg_db_path'
            

            P:S. I have changed aold name class in DichiarativeGlobali.

            1 Reply Last reply
            0
            • D Digitale_GFacchini

              Ok hai have put:

              myObject.settingDichiarative(*argv);
              

              And so it's ok, but now i have error in method settingDichiarative.

              C:\Generale\OneDrive - ELICAT SRL - 03978700288\Developer\QtApplicazioni\youtube_and_web\EVILEG\SQLiteDbAcccesListModel/dichiarative.cpp:14: undefined reference to `dichiarative::paramingresso::arg_db_name'
              

              This error for every idem of structure declared into .h

              struct paramingresso {
                      static QString arg_db_type;
                      static QString arg_db_driver;
                      static QString arg_db_name;
                      static QString arg_db_path;
                  };
              

              and the method is :

              void dichiarative::settingDichiarative(char* argomenti)
              {
                  dichiarative::paramingresso::arg_db_type = QStringLiteral("%1").arg(argomenti[1]);
                  dichiarative::paramingresso::arg_db_driver = QStringLiteral("%1").arg(argomenti[2]);
                  dichiarative::paramingresso::arg_db_name = QStringLiteral("%1").arg(argomenti[3]);
                  dichiarative::paramingresso::arg_db_path = QStringLiteral("%1").arg(argomenti[4]);
              }
              

              In this monts i have sty but it's too much arguments and every time I try to apply I block myself for errors .. Be patient then when I understand bele the logic I will be able to reciprocate. At least I hope

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #9

              @Digitale_GFacchini said in struct and passing array parameters:

              Ok hai have put:
              myObject.settingDichiarative(*argv);

              This is wrong, you should change settingDichiarative(char* argomenti) to settingDichiarative(char** argomenti) and call myObject.settingDichiarative(argv);.

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              1
              • D Offline
                D Offline
                Digitale_GFacchini
                wrote on last edited by
                #10

                Thanks VRonin but .. . Why? in main.cpp i have :

                int main(int argc, char *argv[])
                

                What difference from * to ** ??

                jsulmJ 1 Reply Last reply
                0
                • D Digitale_GFacchini

                  Thanks VRonin but .. . Why? in main.cpp i have :

                  int main(int argc, char *argv[])
                  

                  What difference from * to ** ??

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @Digitale_GFacchini said in struct and passing array parameters:

                  char *argv[]

                  this is same as "char **argv".
                  You should read a book or tutorial about C++ basics.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • D Offline
                    D Offline
                    Digitale_GFacchini
                    wrote on last edited by
                    #12

                    thanks VRonin,
                    topic of * is "pointers". But why two ** ??
                    Do you know any good books in Italian? I'm reading everything in English and I was not using it for years.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      char * = array of char
                      char ** = array of array of char

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2
                      • D Offline
                        D Offline
                        Digitale_GFacchini
                        wrote on last edited by
                        #14

                        Thank SGaist

                        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