gpt4 book ai didi

c++ - 错误 : no match for 'operator+' (operand types are 'const QString' and 'QDate' )

转载 作者:行者123 更新时间:2023-11-28 04:41:20 24 4
gpt4 key购买 nike

<分区>

我确实在声明 QDate 时遇到问题,当我在 DB 插入函数中使用声明的字(值)和相关值时,它会继续提示错误。请指导并纠正我。我已经尽了自己的一份力量,但仍然存在问题;那时我不知道:(

我的代码:

#include "cashregister.h"
#include "ui_cashregister.h"


CashRegister::CashRegister(QWidget *parent) :
QDialog(parent),
ui(new Ui::CashRegister)
{
ui->setupUi(this);

ui->dateEdit->setDate(QDate::currentDate());

ui->groupBox_sales->hide();

ui->pushButton_finish->hide();

ui->tableView->hide();

ui->label_totalAmount->hide();

QTime time = QTime::currentTime();
qsrand((uint)time.msec());
}

CashRegister::~CashRegister()
{
delete ui;
}

void CashRegister::on_pushButton_createNewReceipt_clicked()
{
ui->groupBox_sales->show();

int bigNo, smallNo;
bigNo = 100;
smallNo = 0;

int randomValue = qrand() % ((bigNo + 1) - smallNo) + smallNo;

ui->label_receiptNum->setText("AST" + QString::number(randomValue));

QSqlQueryModel *myModel = new QSqlQueryModel();
QSqlQuery myqry;
myqry.prepare("SELECT ItemId FROM Item");
myqry.exec();
myModel->setQuery(myqry);
ui->comboBox_itemID->setModel(myModel);

myqry.prepare("CREATE TABLE IF NOT EXISTS Receipt (ReceiptId VARCHAR(7) UNIQUE PRIMARY KEY, ReceiptDate DATE, ReceiptAmount DOUBLE)" );
myqry.exec();
myqry.prepare("CREATE TABLE IF NOT EXISTS Sold (ReceiptId VARCHAR(7), ItemId VARCHAR(7), SoldQuantity INTEGER, TotalPrice DOUBLE)" );
myqry.exec();
}

void CashRegister::on_pushButton_next_clicked()
{
ui->tableView->show();
ui->pushButton_finish->show();
ui->label_totalAmount->show();

QString receiptNo = ui->label_receiptNum->text();
QString itemSelect = ui->comboBox_itemID->currentText();
QString qtySold = ui->lineEdit_qtySold->text();
QDate currentDate = QDate::currentDate(); //<--THIS-->//
QString totalAmount = ui->label_totalAmount->text();


double price=0, totalPrice=0;

QSqlQuery myqry;
myqry.exec("SELECT ItemPrice FROM Item WHERE ItemId='"+itemSelect+"' ");
if (myqry.next())
price = myqry.value(0).toDouble();

totalPrice = price * qtySold.toInt();

QString totalPriceString = QString::number(totalPrice);

myqry.prepare("INSERT INTO Sold (ReceiptId, ItemId, SoldQuantity, TotalPrice) VALUES ('"+receiptNo+"', '"+itemSelect+"', '"+qtySold+"', '"+totalPriceString+"') ");
myqry.exec();

ui->comboBox_itemID->setCurrentIndex(0);
ui->lineEdit_qtySold->clear();

myqry.prepare("SELECT Item.ItemId, Item.ItemName, Item.ItemPrice, Sold.SoldQuantity FROM Item, Sold WHERE Item.ItemId = Sold.ItemId AND Sold.ReceiptId='"+receiptNo+"' ");
myqry.exec();

QSqlQueryModel *myModel = new QSqlQueryModel();
myModel->setQuery(myqry);
ui->tableView->setModel(myModel);

double sum = 0;
myqry.exec("SELECT SUM(TotalPrice) FROM Sold WHERE ReceiptId='"+receiptNo+"' ");
if (myqry.next())
sum += myqry.value(0).toDouble();

ui->label_totalAmount->setText("TOTAL AMOUNT: RM" + QString::number(sum));

//<--THIS-->//
myqry.prepare("INSERT INTO Receipt (ReceiptId, ReceiptDate, ReceiptAmount) VALUES ('"+receiptNo+"', '"+currentDate+"', '"+totalAmount+"') ");
myqry.exec();

}

void CashRegister::on_pushButton_finish_clicked()
{
this->close();
}

错误:

C:\Users\joeboy69\Documents\Workshop 1\ASTECHNOWERKZ\cashregister.cpp:100: error: no match for 'operator+' (operand types are 'const QString' and 'QDate')
myqry.prepare("INSERT INTO Receipt (ReceiptId, ReceiptDate, ReceiptAmount) VALUES ('"+receiptNo+"', '"+currentDate+"', '"+totalAmount+"') ");
^

截图:

Screenshot of the Code with Error - View it HERE

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com