-
wrote on 8 May 2018, 10:37 last edited by
/* 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?- main.cpp: In function 'int qMain(int, char**)':
main.cpp:11:43: error: qualified-id in declaration before '(' token
void dichiarative::settingDichiarative(argv);
^ - 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 - main.cpp: In function 'int qMain(int, char**)':
-
@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;
-
wrote on 8 May 2018, 14:48 last edited by
@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?
-
Hi,
No, a class is a definition used to create objects AKA "instances".
-
wrote on 8 May 2018, 16:03 last edited by
@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);
^ -
wrote on 8 May 2018, 16:32 last edited by Digitale_GFacchini 5 Aug 2018, 16:33
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
-
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
-
wrote on 9 May 2018, 10:37 last edited by
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.
-
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
wrote on 9 May 2018, 10:44 last edited by@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)
tosettingDichiarative(char** argomenti)
and callmyObject.settingDichiarative(argv);
. -
wrote on 9 May 2018, 11:33 last edited by
Thanks VRonin but .. . Why? in main.cpp i have :
int main(int argc, char *argv[])
What difference from * to ** ??
-
Thanks VRonin but .. . Why? in main.cpp i have :
int main(int argc, char *argv[])
What difference from * to ** ??
@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. -
wrote on 9 May 2018, 12:48 last edited by
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. -
char *
= array of char
char **
= array of array of char -
wrote on 9 May 2018, 13:01 last edited by
Thank SGaist
1/14