I'm just trying to simplify
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
ABItem *entrynum =
static_cast<ABItem *>(treeWidget->topLevelItem(i));
if(filename == "/0.txt"){
output << entrynum->food() << "\r\n" << endl;
output << endl;
} else if(filename == "/1.txt"){
output << entrynum->calorie() << "\r\n" << endl;
output << endl;
} else if(filename == "/2.txt"){
output << entrynum->protein() << "\r\n" << endl;
output << endl;
} else if(filename == "/3.txt"){
output << entrynum->carb() << "\r\n" << endl;
output << endl;
} else if(filename == "/4.txt"){
output << entrynum->carb() << "\r\n" << endl;
output << endl;
} else if(filename == "/5.txt"){
output << entrynum->fat() << "\r\n" << endl;
output << endl;
} else if(filename == "/6.txt"){
output << entrynum->sugar() << "\r\n" << endl;
output << endl;
} else if(filename == "/7.txt"){
output << entrynum->sodium() << "\r\n" << endl;
output << endl;
} else if(filename == "/8.txt"){
output << entrynum->fiber() << "\r\n" << endl;
output << endl;
}
}
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
ABItem *entrynum =
static_cast<ABItem *>(treeWidget->topLevelItem(i));
if(filename == "/0.txt"){
output << entrynum->food() << "\r\n" << endl;
output << endl;
} else if(filename == "/1.txt"){
output << entrynum->calorie() << "\r\n" << endl;
output << endl;
} else if(filename == "/2.txt"){
output << entrynum->protein() << "\r\n" << endl;
output << endl;
} else if(filename == "/3.txt"){
output << entrynum->carb() << "\r\n" << endl;
output << endl;
} else if(filename == "/4.txt"){
output << entrynum->carb() << "\r\n" << endl;
output << endl;
} else if(filename == "/5.txt"){
output << entrynum->fat() << "\r\n" << endl;
output << endl;
} else if(filename == "/6.txt"){
output << entrynum->sugar() << "\r\n" << endl;
output << endl;
} else if(filename == "/7.txt"){
output << entrynum->sodium() << "\r\n" << endl;
output << endl;
} else if(filename == "/8.txt"){
output << entrynum->fiber() << "\r\n" << endl;
output << endl;
}
}
To copy to clipboard, switch view to plain text mode
to something more like this:
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
ABItem *entrynum =
static_cast<ABItem *>(treeWidget->topLevelItem(i));
if(filename == filename){
output << entrynum->array[i] << "\r\n" << endl;
output << endl;
}
}
for (int i = 0; i < treeWidget->topLevelItemCount(); ++i) {
ABItem *entrynum =
static_cast<ABItem *>(treeWidget->topLevelItem(i));
if(filename == filename){
output << entrynum->array[i] << "\r\n" << endl;
output << endl;
}
}
To copy to clipboard, switch view to plain text mode
The orig. code works fine its just bulky and gross looking was trying to make it look nicer.
Added after 15 minutes:
PS: The outputs are 9 Text files which are named 0.txt, 1.txt, 2.txt ect... and they contain seperate data inside of each for example 0.txt has:
"Food1
Food2" inside of the file
Bookmarks