Hello,
I've been banging my head against this for a while and can only seem to get a blank value returned. I have followed the advice in this thread and this documentation by binding a parameter to QSql::Out. I still seem to get a blank result, even though I know that is wrong as I can call the procedure with a result in SSMS. Am I constructing the query incorrectly? See relevant code below:

Stored procedure definition:
Qt Code:
  1. CREATE procedure [dbo].[usp_SetGetNextRecordID] ( @TableName varchar(50),
  2. @RecordID int OUTPUT )
  3. as begin
  4. set nocount on
  5. update mt_Tables
  6. set LastRecordID = LastRecordID+1,
  7. @RecordID = LastRecordID+1
  8. where TableName = @TableName
  9.  
  10. return
  11. end
  12. GO
To copy to clipboard, switch view to plain text mode 

Function definition for calling stored procedure:
Qt Code:
  1. QString DbController::runProcedureWithOutput(QString procedure_name, QMap<int, QString> values_list)
  2. {
  3. QString return_value;
  4.  
  5. QString query_string = QString("{CALL " + procedure_name + " (");
  6.  
  7. QMapIterator<int, QString> i(values_list);
  8. while (i.hasNext()) {
  9. i.next();
  10. if (i.hasNext() == true) {
  11. query_string += "?,";
  12. } else {
  13. query_string += "?";
  14. }
  15. }
  16.  
  17. query_string.append(")}");
  18.  
  19. QSqlQuery query;
  20.  
  21. query.prepare(query_string);
  22. query.setForwardOnly(true);
  23.  
  24. int bound_out_value = 0; // Default
  25.  
  26. //Bind values...
  27. QMapIterator<int, QString> j(values_list);
  28. while (j.hasNext()) {
  29. j.next();
  30. if (!j.hasNext()) {
  31. query.bindValue(j.key(), j.value(), QSql::Out); // Bind out value if last parameter
  32. bound_out_value = j.key();
  33. } else {
  34. query.bindValue(j.key(), j.value());
  35. }
  36. }
  37.  
  38. query.exec();
  39.  
  40. while(query.next()) {
  41. return_value = query.value(bound_out_value).toString();
  42. }
  43.  
  44. return return_value;
  45. }
To copy to clipboard, switch view to plain text mode 

Usage of function:
Qt Code:
  1. QMap<int, QString> params;
  2. params.insert(0, "table_name");
  3. params.insert(1, "@RecordID");
  4.  
  5. QString result = db_controller->runProcedureWithOutput("usp_SetGetNextRecordID", params);
  6.  
  7. qDebug() << result; // Always empty string when it shouldn't be, no SQL Errors thrown.
To copy to clipboard, switch view to plain text mode 

Any thoughts? Let me know if you need more context or have any questions. Help much appreciated in advance!