Not sure how to provide a minimal program, because of all the dependencies. I'll try to explain where I use the function in more detail those, hope that helps:
I got my main class called "Equilibrizer", which has a Pointer to my DecisionTreeWidget.
class Equilibrizer : public QMainWindow
...
private:
DecisionTreeWidget* tree_w;
The tree_w is initialized in the constructor of Equilibrizer. Now on the click of a button, the method where I get the error is called.
DecisionTree decTree(tree_w->getDecTree());
Right now, getDecTree() looks like the following:
DecisionTree DecisionTreeWidget::getDecTree() {
/* Here I just tried different things in hopes of avoiding that error, nothing worked so far */
QTreeWidgetItemIterator iter(tree);
QString text = (*iter)->text(3);
std::cout << tree->topLevelItem(0)->text(1).toStdString() << std::endl;
/*********/
holdemBoard b;
string2board(tree->topLevelItem(0)->text(4).toStdString(), &b);
DecisionTree result(effectiveStacks, DecisionPt(string2player(tree->topLevelItem(0)->text(1).toStdString()),
tree->topLevelItem(0)->text(2).toFloat(),
tree->topLevelItem(0)->text(3).toFloat(),
EquityArray(b),
string2action(tree->topLevelItem(0)->text(0).toStdString())));
for(int i=1; i<tree->topLevelItemCount(); i++) {
string2board(tree->topLevelItem(i)->text(4).toStdString(), &b);
result.addDecPt(DecisionPt(string2player(tree->topLevelItem(i)->text(1).toStdString()),
tree->topLevelItem(i)->text(2).toFloat(),
tree->topLevelItem(i)->text(3).toFloat(),
EquityArray(b),
string2action(tree->topLevelItem(i)->text(0).toStdString())),
tree->topLevelItem(i)->text(6).toInt());
}
return result;
}
So, it doesn't matter if I use the Iterator, or call the topLevelItem directly, everything gives me the same access violation error.
Lastly, this is the way I add content to the tree, which (at least from the looks of it) works fine.
void DecisionTreeWidget::addChild() {
QTreeWidgetItem* item;
if (!hasRoot) {
item = new QTreeWidgetItem();
tree->addTopLevelItem(item);
effectiveStacks = stacks->value();
}
else {
item = new QTreeWidgetItem();
tree->selectedItems()[0]->addChild(item);
tree->selectedItems()[0]->setExpanded(true);
}
item->setText(0, actionBox->currentText());
item->setText(1, playerBox->currentText());
item->setText(2, QString::number(sbCIPSpin->value()));
item->setText(3, QString::number(bbCIPSpin->value()));
item->setText(4, boardEdit->text());
item->setText(5, QString::number(effectiveStacks));
item->setText(6, QString::number(counter));
tree->setItemSelected(item, true);
tree->setItemSelected(item->parent(), false);
hasRoot = true;
counter++;
}