What does it mean this error
-
Someone know why happen this. I think it's because the list is out range. Other question i can change my index to accept a more big range?
Message:
https://i.imgsafe.org/13d50793d8.pngBye!
-
Hi,
You should rather fix the code to not access something that is outside of your QList.
-
Yes it is. Note that without seeing the code, it's impossible to tell what is going on.
-
@SGaist
Code when i append one item of QTreeWidget in my list:void MainWindow::Example() { int i,j; QTreeWidgetItem *item = new QTreeWidgetItem(); QStringList contactos = cliente.rosterManager().getRosterBareJids(); for(i=0;i<contactos.length();i++) { item->setText(0,contactos[i]); QStringList recursos = cliente.rosterManager().getResources(contactos[i]); for(j=0;j<recursos.length();j++) { AddChild(item); listaItems.append(item); } ui->arbolConectados->addTopLevelItems(listaItems); } } void MainWindow::AddChild(QTreeWidgetItem *parent){ QTreeWidgetItem *item = new QTreeWidgetItem(); parent->addChild(item); }
-
@SGaist Code when i show content of my item's
void MainWindow::content(QString barejid, QString resource) { if(cliente.rosterManager().isRosterReceived() == true) { QIcon online; online.addFile(":/icons/user-online.png"); if(ui->arbolConectados->findItems(barejid,Qt::MatchExactly).size() == 0) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0,barejid); ui->arbolConectados->addTopLevelItem(item); } if(cliente.rosterManager().getPresence(barejid,resource).type() == QXmppPresence::Available) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0,resource); item->setIcon(0,online); ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->addChild(item); } if(cliente.rosterManager().getPresence(barejid,resource).type() == QXmppPresence::Unavailable) { int i=0; while(i<ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->childCount() && ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->child(i)->text(0) != resource) //busqueda lineal { i++; } ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->takeChild(i); if(ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->childCount() == 0) { online.addFile(":/icons/user-offline.png"); } } ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]->setIcon(0,online); } }
-
You are doing doing several assumptions about what findItems returns and the content of that function returns.
Also, why are you calling findItems that many times ?
-
You are doing doing several assumptions about what findItems returns and the content of that function returns.
Also, why are you calling findItems that many times ?
-
You are going to work on the exact same item in all the function then why search for it every time you are going to use it ?
Same goes for the presence type,
-
You are going to work on the exact same item in all the function then why search for it every time you are going to use it ?
Same goes for the presence type,
@SGaist said in What does it mean this error:
You are going to work on the exact same item in all the function then why search for it every time you are going to use it ?
Same goes for the presence type,so i delete the presence it's not necessary ok's
-
That's not what I was saying.
You are writing code that's difficult to read and understand. e.g. there's no need to call
cliente.rosterManager().getPresence(barejid,resource).type()
several time. Just put the returned value in a variable and test that one.Same goes for the QTreeWidgetItem, you need to get the one you are interested in and then only work with that one. This will avoid to have
ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]
through out your method -
That's not what I was saying.
You are writing code that's difficult to read and understand. e.g. there's no need to call
cliente.rosterManager().getPresence(barejid,resource).type()
several time. Just put the returned value in a variable and test that one.Same goes for the QTreeWidgetItem, you need to get the one you are interested in and then only work with that one. This will avoid to have
ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]
through out your method@SGaist Ok i saved the result of presence in a var this works. But when i create a new qtreewidget, this is the code recoded:
void MainWindow::cambioRoster(QString barejid, QString resource) { if(cliente.rosterManager().isRosterReceived() == true) { QXmppPresence::Type a = cliente.rosterManager().getPresence(barejid,resource).type(); QTreeWidgetItem *element = new QTreeWidgetItem(ui->arbolConectados->findItems(barejid,Qt::MatchExactly)[0]); QIcon online; online.addFile(":/icons/user-online.png"); if(ui->arbolConectados->findItems(barejid,Qt::MatchExactly).size() == 0) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0,barejid); ui->arbolConectados->addTopLevelItem(item); } if(a == QXmppPresence::Available) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setText(0,resource); item->setIcon(0,online); element->addChild(item); }else{ int i=0; while(i<element->childCount() && element->child(i)->text(0) != resource) //busqueda lineal { i++; } element->takeChild(i); if(element->childCount() == 0) { online.addFile(":/icons/user-offline.png"); } } element->setIcon(0,online); } }
Show me the before error:
https://i.imgsafe.org/13d50793d8.pngI think because return me a element of one list?
-
Run your application through the debugger, you'll see what triggers that.
-
@SGaist i think in one qtreewidgetitem i can't find element. So i can't use qtreewidget because if i use show me this error ASSERT failure in QList<T>::operator[]: "index out of range", file C:\Qt\5.5\msvc2013_static\include\QtCore/qlist.h, line 545
And when i run with debug show me this:
https://i.imgsafe.org/35f6161b6a.pngI can't use mode debugger ->> this is other problem that i had i dont know why show me this.
But my problem basically is i need to check all time because the values change ? you understand so if i save in one var i dont know the actual value i think . Or i'm wrong?
-
As silly as it may sound: don't access it when you know it's not there.
-
Because you're likely using Visual Studio and you didn't install its debugger.
One simple way to avoid that kind of crash is to check the list size before accessing any of its element.