hi to all, I've centso7.5 and Qt 5.7 in VM. i am tryng to build a program having following code
problem is that when assigning a query value in to a QString variable, program crashes. how to solve it.
mine function is :-
-------------------
Qt Code:
  1. product_record* product_record::product_search(int numb)
  2. {
  3. QString sql = "select * from tableProductRecords where number = ?";
  4. QSqlQuery qry;
  5. qry.prepare(sql);
  6.  
  7. qry.bindValue(0, numb);
  8.  
  9. if(qry.exec())
  10. {
  11. if(qry.next())
  12. {
  13. this->name = qry.value(0).toString();// here program crashes
  14. stock = qry.value(1).toInt();
  15. rate = qry.value(2).toFloat();
  16. number = qry.value(3).toInt();
  17. }
  18. }
  19. return this;
  20. }
To copy to clipboard, switch view to plain text mode 
this is mine header file :-
---------------------------------
Qt Code:
  1. #ifndef PRODUCT_RECORD_H
  2. #define PRODUCT_RECORD_H
  3.  
  4. #include <QObject>
  5. #include <QString>
  6. #include <QSqlDatabase>
  7. #include <QSqlQuery>
  8. #include <QVariant>
  9. #include <QMessageBox>
  10. #include <QSqlError>
  11.  
  12.  
  13. class product_record : public QObject
  14. {
  15. Q_OBJECT
  16.  
  17. QString name;
  18. int stock;
  19. float rate;
  20. int number;
  21.  
  22. public:
  23. product_record();
  24. ~product_record();
  25.  
  26. product_record * product_search(int numb);
  27. void product_modify(int no);
  28.  
  29. // getters and setters
  30.  
  31. QString text_name();
  32. int text_stock();
  33. float text_rate();
  34. int text_number();
  35.  
  36. void setText_name(QString *str);
  37. void setText_stcok(int *i);
  38. void setText_rate(float *f);
  39. void setText_number(int *n);
  40. };
  41.  
  42. #endif // PRODUCT_RECORD_H
To copy to clipboard, switch view to plain text mode