gpt4 book ai didi

c++ - QList 跳过列表中的第一项,为什么?

转载 作者:行者123 更新时间:2023-11-28 02:51:50 24 4
gpt4 key购买 nike

<分区>

这就是我正在做的事情。我有一个正在使用主窗口的软件,以及一个启动以下 managaAttributesDialog 对话框类的操作。当对话框打开时,我在数据库上执行查询并创建一个名为 EAVFittmentProperties 的自定义数据类型对象的列表,它只包含一些用于获取和设置属性的方法,这些属性是数据库索引的 int 和一个 QString,其中包含与该索引关联的名称。一切似乎都工作正常,直到我调用 setUpgGui,将那些 EAVFittmentPropeties 转换为组合框,其中将保存可用值。它是一个制造年份搜索系统,因此我可以存储和检索任何给定车辆的油漆颜色,因此 EAVFitmentProperties 现在拥有 3 个值;品牌、型号和年份。这些组合框的列表中将包含可用的品牌型号和年份。一旦我调用 setUpGui 函数并开始遍历列表以创建组合框,它似乎跳过了第一个值,只创建了模型和年份框。

我对列表中的第一项发生了什么感到非常困惑,所以我有很多调试语句,甚至在调用 setUpGui 函数之前运行相同的迭代并且一切正常。任何人都可以提供任何见解,或者知道发生了什么事吗?如果我可以提供更多信息,请询问,这让我发疯,我很想知道发生了什么。提前谢谢大家!

#include "manageattributesdialog.h"
#include "eavfittmentproperties.h"

#include <QtWidgets>
#include <QtSql>

ManageAttributesDialog::ManageAttributesDialog(QWidget *parent) :
QDialog(parent)
{
QSqlDatabase localdb = QSqlDatabase::database("");
if(localdb.open())
{
QMessageBox::information(this,"Connected","Connection to the Database was Established\n"
"\nStatus: Connected");

QSqlQuery *qry = new QSqlQuery(localdb);

if(qry->exec("SELECT * FROM [ProductHelper].[dbo].[EAV_FittmentProperties]"))
{
int z = 1;
while(qry->next())
{
z++;
qDebug() << qry->value(0).toString();
qDebug() << qry->value(1).toString();

int mX = qry->value(0).toInt();

EAVFittmentProperties *fitmentPropertyOption = new EAVFittmentProperties(this);
fitmentPropertyOption->setIndexID(qry->value(0).toInt());
fitmentPropertyOption->setName(qry->value(1).toString());

fitmentPropertiesList.append(fitmentPropertyOption);

}
qry->finish();
}
else
{
QMessageBox::information(this,"Database Query Failed","Query to the Database could not be completed\n"
"\nStatus: Query Not Completed\nError: " + localdb.lastError().text());
}


localdb.close();

for(int i = 0; i < fitmentPropertiesList.count(); i++)
{
qDebug() << i << " is the number we are on";
qDebug() << fitmentPropertiesList[i]->getIndexID();
qDebug() << fitmentPropertiesList[i]->getName();
}

}
else
{
QMessageBox::information(this,"Not Connected","Connection to the Database could not be Established\n"
"\nStatus: Not Connected\nError: " + localdb.lastError().text());
}

setUpGui();

}

void ManageAttributesDialog::setUpGui()
{
//QFrame *mFrame = new QFrame(this);
QVBoxLayout *mLayout = new QVBoxLayout();

QLabel fitmentHeadingLbl;
fitmentHeadingLbl.setText(tr("Fitment Options"));

mLayout->addWidget(&fitmentHeadingLbl);
fitmentPropertiesList.begin();

qDebug() << fitmentPropertiesList.count();

for(int j = 0; j < fitmentPropertiesList.count(); j++)
{
qDebug() << j << " is the number we are on";
qDebug() << fitmentPropertiesList[j]->getIndexID();
int sInt = fitmentPropertiesList[j]->getIndexID();
qDebug() << fitmentPropertiesList[j]->getName();
QString sString = fitmentPropertiesList[j]->getName().toLatin1();
qDebug() << sInt;
qDebug() << sString;
fitmentPropertyLayout[j] = new QVBoxLayout();
QVBoxLayout *thisLayout = fitmentPropertyLayout[j];
fitmentPropertyLabel[j] = new QLabel();
QString sString = fitmentPropertiesList[j]->getName().toLatin1();
qDebug() << sString;
fitmentPropertyLabel[j]->setText(sString);
fitmentPropertyCombo[j] = new QComboBox();
thisLayout->addWidget(fitmentPropertyLabel[j]);
thisLayout->addWidget(fitmentPropertyCombo[j]);

//mLayout->addLayout(thisLayout);
}

//mFrame->setLayout(mLayout);
this->setMinimumSize(400,400);
this->setLayout(mLayout);
}

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