after you questioned ( where you initialized prdRecord) then I modify code and added prdRecord as argument of product_search.
after modification :-
product_record* product_record::product_search(int numb, product_record *prdRecord)
{
QString sql
= "select * from tableProductRecords where number = ?";
qry.prepare(sql);
qry.bindValue(0, numb);
if(qry.exec())
{
if(qry.next())
{
prdRecord->name = qry.value(0).toString().trimmed();// here program crashes
prdRecord->stock = qry.value(1).toInt();
prdRecord->rate = qry.value(2).toFloat();
prdRecord->number = qry.value(3).toInt();
}
}
return prdRecord;
}
product_record* product_record::product_search(int numb, product_record *prdRecord)
{
QString sql = "select * from tableProductRecords where number = ?";
QSqlQuery qry;
qry.prepare(sql);
qry.bindValue(0, numb);
if(qry.exec())
{
if(qry.next())
{
prdRecord->name = qry.value(0).toString().trimmed();// here program crashes
prdRecord->stock = qry.value(1).toInt();
prdRecord->rate = qry.value(2).toFloat();
prdRecord->number = qry.value(3).toInt();
}
}
return prdRecord;
}
To copy to clipboard, switch view to plain text mode
and here i called this with initialization of perdRecord
void dialogAddNewRecord::on_pushButtonSearchByNumber_clicked()
{
QString str
= ui
->lineEditNumber
->text
().
trimmed();
int s = str.toInt();
prdRecord = new product_record();
if(s)
{
QMessageBox::information(this,
"on_pushButtonSearchByNumber_clicked",
QString::number(s
) );
product_record * prd = product_record::product_search(s, prdRecord);
ui->lineEditName->setText(prd->text_name());
ui
->lineEditStock
->setText
(QString::number(prd
->text_stock
()));
ui
->lineEditRate
->setText
(QString::number(prd
->text_rate
()));
ui
->lineEditNumber
->setText
(QString::number(prd
->text_number
()));
}
else
{
QMessageBox::information(this,
"on_pushButtonSearchByNumber_clicked",
"number not valid");
}
}
void dialogAddNewRecord::on_pushButtonSearchByNumber_clicked()
{
QString str = ui->lineEditNumber->text().trimmed();
int s = str.toInt();
prdRecord = new product_record();
if(s)
{
QMessageBox::information(this, "on_pushButtonSearchByNumber_clicked", QString::number(s) );
product_record * prd = product_record::product_search(s, prdRecord);
ui->lineEditName->setText(prd->text_name());
ui->lineEditStock->setText(QString::number(prd->text_stock()));
ui->lineEditRate->setText(QString::number(prd->text_rate()));
ui->lineEditNumber->setText(QString::number(prd->text_number()));
}
else
{
QMessageBox::information(this, "on_pushButtonSearchByNumber_clicked", "number not valid");
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks