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.
  • D Offline
    D Offline
    Digitale_GFacchini
    wrote on 8 May 2018, 10:37 last edited by
    #1
    /* file dichiarative.h */
    #ifndef DICHIARATIVE_H
    #define DICHIARATIVE_H
    #include <QString>
    
    class dichiarative {
    
    public:
        dichiarative();
    
        struct paramingresso {
            static QString arg_db_type;
            static QString arg_db_driver;
            static QString arg_db_name;
            static QString arg_db_path;
        };
    
        void settingDichiarative(char* argomenti);
    };
    
    #endif // DICHIARATIVE_H
    
    /* file dichiarative.cpp */
    #include "dichiarative.h"
    dichiarative::dichiarative()
    {
    
    }
    
    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];
    }
    
    /* file main.cpp */
    int main(int argc, char *argv[])
    {
        void dichiarative::settingDichiarative(argv);
    
       QString pippo = dichiarative::paramingresso.arg_db_driver;
    ..
    }
    
    

    Please help me. I'm beginner in C++.
    Why i have this two error?

    1. main.cpp: In function 'int qMain(int, char**)':
      main.cpp:11:43: error: qualified-id in declaration before '(' token
      void dichiarative::settingDichiarative(argv);
      ^
    2. main.cpp:13:47: error: expected primary-expression before '.' token
      QString pippo = dichiarative::paramingresso.arg_db_driver;
      ^

    For error 1 I have try "cahr* argv", "*argv", "argv[]" but everyone whith different error.

    Thanks.
    Gianfranco

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 8 May 2018, 11:58 last edited by
      #2

      @Digitale_GFacchini said in struct and passing array parameters:

      void dichiarative::settingDichiarative(argv);

      You have not created an object. Try this:

      dichiarative myObject;
      myObject.settingDichiarative(argv);
      QString pippo = myObject.paramingresso.arg_db_driver;
      

      (Z(:^

      1 Reply Last reply
      3
      • D Offline
        D Offline
        Digitale_GFacchini
        wrote on 8 May 2018, 14:48 last edited by
        #3

        @Digitale_GFacchini said in struct and passing array parameters:

        dichiarative

        Sorry sierdzio, but dichiarative it's a class. the class is a object. or no?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 8 May 2018, 14:50 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 8 May 2018, 16:03 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 8 May 2018, 16:32 last edited by Digitale_GFacchini 5 Aug 2018, 16:33
              #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 9 May 2018, 10:44
              0
              • S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 8 May 2018, 17:54 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 9 May 2018, 10:37 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
                    8 May 2018, 16:32

                    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 9 May 2018, 10:44 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 9 May 2018, 11:33 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 9 May 2018, 11:47
                      0
                      • D Digitale_GFacchini
                        9 May 2018, 11:33

                        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 9 May 2018, 11:47 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 9 May 2018, 12:48 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
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 9 May 2018, 12:52 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 9 May 2018, 13:01 last edited by
                              #14

                              Thank SGaist

                              1 Reply Last reply
                              0

                              1/14

                              8 May 2018, 10:37

                              • Login

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