gpt4 book ai didi

c++ - QList::at 中的 Qt ASSERT 失败:“索引超出范围

转载 作者:行者123 更新时间:2023-12-02 11:54:54 26 4
gpt4 key购买 nike

我一直在我的程序中使用QString列表,但是当我第二次更改组合框的索引时它们会中断(通过中断我的意思是程序正在崩溃)并且我不确定为什么。使用 QStringLists 的唯一代码是

void Search::on_comboBox_Tabel_Select_currentIndexChanged(int index)
{
QStringList customer = (QStringList() << "Customer_ID" << "Company Name" << "City" << "Phone Number" << "Street Adress"
<< "County" << "BULSTAT" << "Company Owner" << "Account Since");
QStringList invoice = (QStringList() << "Invoice Number" << "Date Time" << "Total Purchased" << "Company Name" << "Company Owner");
QStringList product = (QStringList() << "Product Code" << "Product Name" << "Product Quantity"
<< "Reorder Level" << "Max Product Quantity" << "Product Purchase Cost"
<< "Selling Price" << "Selling Price VAT");
switch(index)
{
case 0:
{
ui->comboBox_select->clear();
ui->comboBox_select->addItems(customer);
break;
}
case 1:
{
ui->comboBox_select->clear();
ui->comboBox_select->addItems(invoice);
break;
}
case 2:
{
ui->comboBox_select->clear();
ui->comboBox_select->addItems(product);
break;
}
}

}

void Search::CreatQuery()
{
QStringList customer = (QStringList() << "Customer_ID" << "Company_Name" << "City" << "Phone_Number" << "Street_Adress"
<< "County" << "BULSTAT" << "Company_Owner" << "Account_Since");
QStringList invoice = (QStringList() << "Invoice_Number" << "Date_Time" << "Total_Purchased");
QStringList product = (QStringList() << "Product_CODE" << "Product_Name" << "ProductQ"
<< "Reorder_Level" << "Max_Product_Quantity" << "Product_Purchase_Cost"
<< "Selling_Price" << "Selling_Price_VAT");
QStringList tabel = (QStringList() << "Customer" << "Invoice" << "Product");
int tabelIndex = ui->comboBox_Tabel_Select->currentIndex();
int columnIndex = ui->comboBox_select->currentIndex();
QString TabelData = tabel.at(tabelIndex).toLocal8Bit().constData();
QString ColumnData;
QString Parameter = ui->lineEdit->text();
switch (tabelIndex)
{
case 0:
ColumnData = customer.at(columnIndex).toLocal8Bit().constData();
break;
case 1:
ColumnData = invoice.at(columnIndex).toLocal8Bit().constData();
break;
case 2:
ColumnData = product.at(columnIndex).toLocal8Bit().constData();
break;
}
if(ButtonPressed == "BETWEEN")
{
QString ParameterBetween = ui->lineEdit_between->text();
query = "SELECT * FROM " + TabelData + " WHERE " + ColumnData + " BETWEEN " + Parameter + " AND " + ParameterBetween;
}
else
{
query = "SELECT * FROM " + TabelData + " WHERE " + ColumnData + " " + ButtonPressed + " " + Parameter;
}
ui->textEdit->setText(query);
}

最佳答案

我想我已经成功重现了您的问题。

on_comboBox_Tabel_Select_currentIndexChanged中有一行:

QStringList invoice  = (QStringList() << "Invoice Number"
<< "Date Time"
<< "Total Purchased"
<< "Company Name"
<< "Company Owner");

CreatQuery中有一行:

QStringList invoice  = (QStringList() << "Invoice_Number"
<< "Date_Time"
<< "Total_Purchased");

因此,当您选择公司名称或公司所有者时,索引超出范围。

关于c++ - QList<T>::at 中的 Qt ASSERT 失败:“索引超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27692313/

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