KeineAhnung
22nd April 2014, 23:40
Hi there,
I am trying to pass on a QSqlQuery result, which is one line from a SQLite database, to an object. Is that possible and if so how should the syntax be?
I tried to use QSqlQuery as a data type but I guess that is not correct:
.../mainwindow.cpp:70: Error: no matching constructor for initialization of 'Employee'
team[sIndex] = Employee(qry, level);
^ ~~~~~~~~~~
.../employee.h:9: candidate constructor not viable: no known conversion from 'QSqlQuery *' to 'const QSqlQuery' for 1st argument; dereference the argument with *
Employee(const QSqlQuery &query, const QString &level);
^
If this would be the right way, what would be the correct data type?
My goal is to create a Qvector<Employee> called team that holds all the team members. The employee objects within the vector shall hold a bunch of information from a SQLite database. After selecting the right employee in my GUI the correct data (one row from the db) should be loaded and a new employee object should be created. Within the class Employee the basic data should be reworked. I am not interested in the basic data from the db but the parameters that could be calculated from the basic data. So I would like to pass on the query result to the object and have the class do all the conversion.
Is this a clever way to do that or am I barking up the wrong tree?
The code works as long as I use two QStrings, with the exception that I cannot declare the vector Qvector<Employee> team without the two arguments defined in the class. So far I was not able to find a work around that issue. How can I declare an empty vector from the class Employee without passing on any values?
Thanks for your input in advance!
I am trying to pass on a QSqlQuery result, which is one line from a SQLite database, to an object. Is that possible and if so how should the syntax be?
I tried to use QSqlQuery as a data type but I guess that is not correct:
.../mainwindow.cpp:70: Error: no matching constructor for initialization of 'Employee'
team[sIndex] = Employee(qry, level);
^ ~~~~~~~~~~
.../employee.h:9: candidate constructor not viable: no known conversion from 'QSqlQuery *' to 'const QSqlQuery' for 1st argument; dereference the argument with *
Employee(const QSqlQuery &query, const QString &level);
^
If this would be the right way, what would be the correct data type?
My goal is to create a Qvector<Employee> called team that holds all the team members. The employee objects within the vector shall hold a bunch of information from a SQLite database. After selecting the right employee in my GUI the correct data (one row from the db) should be loaded and a new employee object should be created. Within the class Employee the basic data should be reworked. I am not interested in the basic data from the db but the parameters that could be calculated from the basic data. So I would like to pass on the query result to the object and have the class do all the conversion.
Is this a clever way to do that or am I barking up the wrong tree?
The code works as long as I use two QStrings, with the exception that I cannot declare the vector Qvector<Employee> team without the two arguments defined in the class. So far I was not able to find a work around that issue. How can I declare an empty vector from the class Employee without passing on any values?
Thanks for your input in advance!