TITLE|VARIABLE1:NAME1:VALUE1|VARIABLE2:NAME2:VALUE2|
TITLE|VARIABLE1:NAME1:VALUE1|VARIABLE2:NAME2:VALUE2|
To copy to clipboard, switch view to plain text mode
class MyQTableWidget { //..// private: std::vector<std::string*> results; //...// };
int MyQTableWidget::getDataFromFile(const char* v_szText, const char v_szDelimiter)
{
std::ifstream inf(v_szText);
std::string buf;
std::string name;
std::string label;
std::string value;
while(!std::getline(inf, buf, v_szDelimiter).eof()) {
std::stringstream str(buf, std::stringstream::in);
std::getline(str, name, ':');
std::getline(str, label, ':');
std::getline(str, value);
results.push_back(new std::string(name));
results.push_back(new std::string(label));
results.push_back(new std::string(value));
} // while
int range = results.size() < 20 ? results.size() : 20; // show only 20 items
for(int i = 0; i < range; i++) {
this->setRowCount(i + 1);
this->setItem(i, 0, iLabel);
this->setItem(i, 1, iValue);
}
vbar->setMinimum(0);
vbar->setMaximum(results.size());
vbar->setEnabled(true);
vbar->setValue(0);
this->setVerticalScrollBar(vbar);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// ... //
} // getDataFromFile
class MyQTableWidget { //..// private: std::vector<std::string*> results; //...// };
int MyQTableWidget::getDataFromFile(const char* v_szText, const char v_szDelimiter)
{
std::ifstream inf(v_szText);
std::string buf;
std::string name;
std::string label;
std::string value;
QTableWidgetItem* iLabel;
QTableWidgetItem* iValue;
while(!std::getline(inf, buf, v_szDelimiter).eof()) {
std::stringstream str(buf, std::stringstream::in);
std::getline(str, name, ':');
std::getline(str, label, ':');
std::getline(str, value);
results.push_back(new std::string(name));
results.push_back(new std::string(label));
results.push_back(new std::string(value));
} // while
int range = results.size() < 20 ? results.size() : 20; // show only 20 items
for(int i = 0; i < range; i++) {
iLabel = new QTableWidgetItem(tr((*(results[2*i])).c_str()));
iValue = new QTableWidgetItem(tr((*(results[2*i+1])).c_str()));
this->setRowCount(i + 1);
this->setItem(i, 0, iLabel);
this->setItem(i, 1, iValue);
}
vbar = new QScrollBar(this);
vbar->setMinimum(0);
vbar->setMaximum(results.size());
vbar->setEnabled(true);
vbar->setValue(0);
this->setVerticalScrollBar(vbar);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
// ... //
} // getDataFromFile
To copy to clipboard, switch view to plain text mode
Bookmarks