我有一个发票表格,我用它来创建发票并显示存储的发票结果。当我尝试从数据库中读取数据并显示时,我遇到了以下错误:
什么导致了这个错误?
我不理解为什么会出现这种情况。我尝试运行的查询将返回4行数据。我的代码如下:QTableWidget:无法插入已被另一个QTableWidget拥有的项目 QTableWidget:无法插入已被另一个QTableWidget拥有的项目 QTableWidget:无法插入已被另一个QTableWidget拥有的项目 QTableWidget:无法插入已被另一个QTableWidget拥有的项目 QTableWidget:无法插入已被另一个QTableWidget拥有的项目
QString CompanyID;
int row = 0;
ui->comboBox_Invoice_Account_Search->setCurrentIndex(1);
QSqlQuery Account_Name_Query;
QTableWidgetItem *Qty_Search = new QTableWidgetItem();
QTableWidgetItem *Description_Search = new QTableWidgetItem();
QTableWidgetItem *Product_Code_Search = new QTableWidgetItem();
QTableWidgetItem *Unit_Price_Search = new QTableWidgetItem();
QTableWidgetItem *Total_Price_Search = new QTableWidgetItem();
while(Query.next())
{
CompanyID = Query.value(10).toString();
//qDebug() << "CompanyID " << CompanyID;
ui->lineEdit_Invoice_VAT->setText(Query.value(9).toString());
ui->lineEdit_Invoice_Total->setText(Query.value(8).toString());
ui->lineEdit_Goods_Total->setText(Query.value(7).toString());
Qty_Search->setText(Query.value(3).toString());
Description_Search->setText(Query.value(4).toString());
Product_Code_Search->setText(Query.value(5).toString());
Unit_Price_Search->setText(Query.value(6).toString());
Total_Price_Search->setText(Query.value(7).toString());
ui->tableWidget_Invoice->setItem(row, 0, Qty_Search);
ui->tableWidget_Invoice->setItem(row, 1, Description_Search);
ui->tableWidget_Invoice->setItem(row, 2, Product_Code_Search);
ui->tableWidget_Invoice->setItem(row, 3, Unit_Price_Search);
ui->tableWidget_Invoice->setItem(row, 4, Total_Price_Search);
row++;
Account_Name_Query.prepare("SELECT Company_Name FROM Customer WHERE Company_ID = '"+ CompanyID +"'");
Account_Name_Query.exec();
while(Account_Name_Query.next())
{
ui->lineEdit_Invoice_Account->setText(Account_Name_Query.value(0).toString());
}
}
什么导致了这个错误?