PDA

View Full Version : Extracting data from appended row



JediSpam
15th September 2011, 02:20
I am trying to grab a specific part of a row upon selection and send the data as the original data type it was (uint32_t). Here are the pieces of code relevant:



QList<QStandardItem *> MainWindow::prepareRow(uint32_t ID, const QString &first, const QString &second, const QString &third)
{
QList<QStandardItem *> rowItems;
QStandardItem *ptr = new QStandardItem(first);
rowItems << ptr;
ptr = new QStandardItem(second);
rowItems << ptr;
ptr = new QStandardItem(third);
rowItems << ptr;

QString tmp;
QTextStream uniquetmp(&tmp);
uniquetmp << ID;

ptr = new QStandardItem(tmp);
rowItems << ptr;

return rowItems;
}

that's how I am placing ID in



void MainWindow::alarm(uint32_t UniqueID, DateTimeType EventTime, QString Hosts, QString Name)
{
QString tmp;
QTextStream event_time(&tmp);
event_time.setFieldWidth(1);
event_time << EvenTime.Hour << QString(":") << EventTime.Min << QString(":") << EventTime.Sec;

bool found= false;
std::vector<iterator it = Alarms.begin();
while (it != Alarms.end())
{
std::string temp1 = Name.toLatin1();
std::string temp2 = it->name;
if (Name.compare(it->name.c_str()) == 0)
{
found = true;
break;
}
}
if (found)
{
QList<QStandardItem *> preparedRow = prepareRow(ID, tmp, HostName, it->brief.c_str());
QStandardItem *itemd1 = standardModel->invisibleRootItem();
itemd1->appendRow(preparedRow);
}

}


Now I'm trying to remove a specific row with the following function. Upon removing it, I want to get ID back and into type uint32_t. Any suggestions?


void MainWindow::Remove()
{
QItemSelectionModel *selected = ui.view->selectionModel();
QModelIndexList rowList = selected->selectedRows();

foreach(QModelIndex rowIndex, rowList) {
standardModel->removeRow(rowIndex.row(), rowIndex.parent());

//I'm guessing i want to grab it here? Don't know how to specify that I only want ID and want to convert to uint32_t
}
}

ChrisW67
15th September 2011, 03:05
QVariant::toUInt() seems a likely candidate if you use data() to get the value, or QString::toUint()/toULong() if you use text().

JediSpam
15th September 2011, 04:07
Thanks I will try that out and let you know!