I am not an expert in C ++ or Qt and I am not able to debug your code.
But just because of curiosity, I began to examine your code and found a suspicious line (second) in your code:
mysql_result result = engine::get_mysql().create_result("SELECT * FROM members WHERE member_id = ?");
Since I am not an expert, and you did not provide any includes , I do not know what your engine namespace is, nor the return type of the get_mysql() function, nor create_result .
So, I guessed a little: get_mysql() possibly returned a QSqlDatabase object? is not it?
But this type does not support any create_result method! So I got stuck there.
Next thanks google I found your one more question made a week ago. I would like to add such important information to your post next time so that people can see your classes and functions, such as:
mysql_result mysql::create_result(QString query) { return mysql_result(this->db.exec(query)); }
and
mysql_result::mysql_result(QSqlQuery query) { this->query = query; }
Now I can understand what this second line of your code is trying to do.
I see a suspicious thing here return mysql_result(this->db.exec(query)); . This is similar to the names of the functions you are trying to execute and get the result from the mysql server.
But according to the algorithm that I see in your member_controller::get_member , it seems to me that you only prepare at the stage, but do not execute it. I see that the Qt Documentation is not clear enough (and again I am not an expert) because: Executes an SQL statement in the database and returns a QSqlQuery Object. And technically you can say that you have QSqlQuery as a result, and you can expect this result to be exactly the same as if you did:
//mysql_result mysql::create_result(QString query) QSqlQuery mysql::query_prepare(QString query) { QSqlQuery query(this->db); query.prepare(query); this->query = query; return this->query; }
But IMHO this is not so. In your case, this has already been done, so you cannot bind any parameter later. So I suggest you change your mysql_result mysql::create_result(QString query) or create another QSqlQuery mysql::query_prepare(QString query) function that makes more sense to me. and change your first lines of code to:
member* member_controller::get_member(int id) { QSqlQuery query = engine::get_mysql().query_prepare("SELECT * FROM members WHERE member_id = ?"); query.addBindValue(value); if (query.exec() && query.first()) ... ...
And in the very last paragraph, I donβt understand why you are trying to invent a shadow? If you already have mysql Qt classes that look very good to me, why are you creating your own class and methods with a single line to call the Qt method, for example:
void mysql_result::add_parameter(QVariant value) { this->queryObject.addBindValue(value); }
Sorry, but IMHO this is not a good idea and almost does not make sense.
UPDATE Having looked at the updated code, I see:
result.bindValue(":mem_id", id);
where result a QSqlQuery type, so you call the native bindValue method, where the second parameter is const QVariant & val according to the documentation. Therefore, I would change your call to:
result.bindValue(":mem_id", QVariant(id));
or
QVariant mem_id(id); result.bindValue(":mem_id", mem_id);