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 :-
-------------------
product_record* product_record::product_search(int numb)
{
QString sql
= "select * from tableProductRecords where number = ?";
qry.prepare(sql);
qry.bindValue(0, numb);
if(qry.exec())
{
if(qry.next())
{
this->name = qry.value(0).toString();// here program crashes
stock = qry.value(1).toInt();
rate = qry.value(2).toFloat();
number = qry.value(3).toInt();
}
}
return this;
}
product_record* product_record::product_search(int numb)
{
QString sql = "select * from tableProductRecords where number = ?";
QSqlQuery qry;
qry.prepare(sql);
qry.bindValue(0, numb);
if(qry.exec())
{
if(qry.next())
{
this->name = qry.value(0).toString();// here program crashes
stock = qry.value(1).toInt();
rate = qry.value(2).toFloat();
number = qry.value(3).toInt();
}
}
return this;
}
To copy to clipboard, switch view to plain text mode
this is mine header file :-
---------------------------------
#ifndef PRODUCT_RECORD_H
#define PRODUCT_RECORD_H
#include <QObject>
#include <QString>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QVariant>
#include <QMessageBox>
#include <QSqlError>
class product_record
: public QObject{
Q_OBJECT
int stock;
float rate;
int number;
public:
product_record();
~product_record();
product_record * product_search(int numb);
void product_modify(int no);
// getters and setters
int text_stock();
float text_rate();
int text_number();
void setText_stcok(int *i);
void setText_rate(float *f);
void setText_number(int *n);
};
#endif // PRODUCT_RECORD_H
#ifndef PRODUCT_RECORD_H
#define PRODUCT_RECORD_H
#include <QObject>
#include <QString>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QVariant>
#include <QMessageBox>
#include <QSqlError>
class QMessageBox;
class product_record : public QObject
{
Q_OBJECT
QString name;
int stock;
float rate;
int number;
public:
product_record();
~product_record();
product_record * product_search(int numb);
void product_modify(int no);
// getters and setters
QString text_name();
int text_stock();
float text_rate();
int text_number();
void setText_name(QString *str);
void setText_stcok(int *i);
void setText_rate(float *f);
void setText_number(int *n);
};
#endif // PRODUCT_RECORD_H
To copy to clipboard, switch view to plain text mode
Bookmarks