简体   繁体   English

Qt C ++来自所选行的数据

[英]Qt C++ Data from a selected row

My row has 5 columns and I need the data from the last column. 我的行有5列,我需要最后一列的数据。 I've written the below function. 我写了下面这个函数。 This function should return the element from the last column of the selected row, but unfortunately, after debug I've noticed that my function only reads the first column. 这个函数应该从所选行的最后一列返回元素,但不幸的是,在调试之后我注意到我的函数只读取了第一列。 Can anyone help me to solve this? 任何人都可以帮我解决这个问题吗?

QString MainWindow::getIDNumberFromSelectedRow(const QModelIndexList indexes)
{
    QStringList selected_text;
    foreach(QModelIndex current,indexes)
    {
        QVariant data = model->data(current);
        QString text = data.toString();
        selected_text.append(text);
        qDebug() << text;
    }

    QString idNumber = selected_text.last();
    return idNumber;
}

Possibly, indexes, and thus, current(s) refers to the first column of the model. 可能,索引以及当前(s)指的是模型的第一列。 What if you refer directly to a specific item, eg: 如果您直接提及特定项目,例如:

model->data(model->index(current.row(), 4))

I don't know if this work, anyway I hope it'll help 我不知道这是否有用,无论如何我希望它会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM