-
Hi,
No, a class is a definition used to create objects AKA "instances".
-
@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);
^ -
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
-
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
@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);
. -
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. -
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 -
Thank SGaist