M
M
Mercury132022-04-09 08:19:53
Qt
Mercury13, 2022-04-09 08:19:53

QAbstractItemModel::beginInsertRows: what happens if the insert fails?

In a descendant of QAbstractItemModel , the insert function may say: insert is not possible for some reason. We do not throw out accidents, we check error codes.
1. How will endInsertRows behave in such a situation?
2. Is it possible to change data classes outside of beginInsertRows/endInsertRows and do nothing between these functions?
3. And if both are not available, what is the best insert architecture to come up with?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2022-04-09
@Mercury13

So far I've come up with this design...

class Committer {  // interface
public:
  virtual void commit() = 0;
  virtual ~Committer() = default;
}

enum class ErrCode { OK, UNCLONEABLE, BAD_RECIPIENT };

struct CommitObj {
  ErrCode errCode;
  std::unique_ptr<Committer> action;
}

class UiObj {
public:
  virtual CommitObj startClone(std::shared_ptr<UiObj> recipient) = 0;
}

We either get an object for which it is sufficient to give commit() in a protected block, or a reason why cloning is not possible.

G
Grigory, 2022-04-09
@Griglapidus

What problem are you trying to solve?
beginInsertRows/endInsertRows are needed to notify views about insertion.
It's hard for me to imagine a situation in which you called beginInsertRows but failed to insert data. If there are concerns, you can check the data in advance and only then insert them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question