It is not a good idea to modify the list in the for lloop
void DPTWidget::disableWidgets(QList<QWidget*> except){
qDebug() << "Search started ON: " << parentWidget()->parentWidget()->objectName();
listOfWidgets = parentWidget()->parentWidget()->findChildren<QWidget *>();
for (int i = 0; i < listOfWidgets.size(); i++) {
qDebug() << "Objectname: " << listOfWidgets.at(i)->objectName();
if(!except.contains(listOfWidgets.at(i))){
if(listOfWidgets.at(i)->isEnabled() == false)
listOfWidgets.removeAt(i); //<<<<<<<<<<<<<<<<<<<<<< listOfWidgets.size() is modified here, also you will miss the i'th item in the list
else
listOfWidgets.at(i)->setEnabled(false);
}
else
listOfWidgets.removeAt(i); //<<<<<<<<<<<<<<<<<<<<<< listOfWidgets.size() is modified here, also you will miss the i'th item in the list
}
}
void DPTWidget::disableWidgets(QList<QWidget*> except){
qDebug() << "Search started ON: " << parentWidget()->parentWidget()->objectName();
listOfWidgets = parentWidget()->parentWidget()->findChildren<QWidget *>();
for (int i = 0; i < listOfWidgets.size(); i++) {
qDebug() << "Objectname: " << listOfWidgets.at(i)->objectName();
if(!except.contains(listOfWidgets.at(i))){
if(listOfWidgets.at(i)->isEnabled() == false)
listOfWidgets.removeAt(i); //<<<<<<<<<<<<<<<<<<<<<< listOfWidgets.size() is modified here, also you will miss the i'th item in the list
else
listOfWidgets.at(i)->setEnabled(false);
}
else
listOfWidgets.removeAt(i); //<<<<<<<<<<<<<<<<<<<<<< listOfWidgets.size() is modified here, also you will miss the i'th item in the list
}
}
To copy to clipboard, switch view to plain text mode
Try the following
void DPTWidget::disableWidgets(QList<QWidget*> except){
qDebug() << "Search started ON: " << parentWidget()->parentWidget()->objectName();
listOfWidgets = parentWidget()->parentWidget()->findChildren<QWidget *>();
int i = 0;
while(i < listOfWidgets.size()) {
qDebug() << "Objectname: " << listOfWidgets.at(i)->objectName();
if(!except.contains(listOfWidgets.at(i))){
if(listOfWidgets.at(i)->isEnabled() == false)
{
listOfWidgets.removeAt(i);
continue;
}
else
listOfWidgets.at(i)->setEnabled(false);
}
else
{
listOfWidgets.removeAt(i);
continue;
}
i++;
}
}
void DPTWidget::disableWidgets(QList<QWidget*> except){
qDebug() << "Search started ON: " << parentWidget()->parentWidget()->objectName();
listOfWidgets = parentWidget()->parentWidget()->findChildren<QWidget *>();
int i = 0;
while(i < listOfWidgets.size()) {
qDebug() << "Objectname: " << listOfWidgets.at(i)->objectName();
if(!except.contains(listOfWidgets.at(i))){
if(listOfWidgets.at(i)->isEnabled() == false)
{
listOfWidgets.removeAt(i);
continue;
}
else
listOfWidgets.at(i)->setEnabled(false);
}
else
{
listOfWidgets.removeAt(i);
continue;
}
i++;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks