T
T
Tesla4o2018-08-23 08:27:59
Qt
Tesla4o, 2018-08-23 08:27:59

Question on QTableView, how to split rows into cells from one QlineEdit?

I can't figure out how to fill multiple lines that are passed from one lineEdit, for example, with a line separator (such as a semicolon or a space).
Now I have code like this for inserting a row:

QStandardItemModel *model = new QStandardItemModel();
    QStandardItem *item;

    for (auto x : tx->AddrsTo) {
        for (int i = 0; i < tx->AddrsTo.size(); ++i) {
            item = new QStandardItem(QString::fromStdString(x));
            model->setItem(0, i, item);
        }
    }

    this->findChild<QTableView*>("Adresses_tableView")->setModel(model);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-08-23
@Tesla4o

use split
doc.qt.io/qt-5/qstring.html#split

spoiler
QStandardItemModel *model = new QStandardItemModel();
for (auto& x : tx->AddrsTo) 
{
  Qstring s(x.c_str()); 
  QStringList items = s.split(';');
  int sz = items.size();
  for(int i = 0; i < sz; ++i)
  {
    model->setItem(0, i, new QStandardItem(items[i]));
  }
}
this->findChild<QTableView*>("Adresses_tableView")->setModel(model);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question