QList::at 中的 Qt 断言失败<T>:"索引超出范围
Qt ASSERT failure in QList<T>::at: "index out of range
我一直在我的程序中使用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");
因此,当您选择"公司名称"或"公司所有者"时,索引超出了范围。
相关文章:
- 为什么在全局范围内使用"extern int a"似乎不行?
- 尝试通过多个向量访问变量时,向量下标超出范围
- 错误:未在此范围内声明'reverse'
- 正在将指针转换为范围
- 使用std::transform将一个范围的元素添加到另一个范围中
- 在基于范围的for循环中使用结构化绑定声明
- 如何计算数据类型的范围,例如int
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 在C++中查找范围的长度
- 如何设置一个范围来提取我想要获得的信息
- 并行用于C++17中数组索引范围内的循环
- 为左值和右值的包装器实现C++范围
- 求出有多少个数字是完美平方,而sqrt()是L,R范围内的素数
- EASTL矢量<向量<int>>连续的
- 关于:C++中异常对象的范围:为什么我没有得到副本?
- 超出范围时使用对象
- 不计算一个范围内的完美数
- ";结果类型必须是可从输入范围的值类型""构造的;创建std::vector时
- 基于范围的 for 循环:迭代使用一个元素扩展的向量
- 如何访问超出其块范围的对象?