有没有办法将QTableWidget中的整数数据显示为十六进制



我有一个从QTableWidget继承的类,名为InsnTable,它的一列具有积分数据。。。我想将整数显示为32位十六进制值。有简单的方法吗?我认为将数据存储为QStrings而不是int,并相应地将整数转换为十六进制。。。在我的情况下,问题是我必须不断地搜索该列中的值,所以我必须将每个数据项转换回整数才能成功搜索。。。那么,有没有一种方法可以只";视图";此列为十六进制值,但它们是否定期存储为整数?

我插入整数数据如下:

void InsnTable::insertInsn(const InsnEntry &insn)
{
this->insertRow(this->rowCount());
QTableWidgetItem *addrValue = new QTableWidgetItem();
uint64_t addr = insn.addr();
addrValue->setData(Qt::EditRole, QVariant::fromValue(addr));
this->setItem(this->rowCount() - 1, 0, addrValue);
}

确定:

你可以在你做的部分:

QVariant::fromValue(addr)

给定一个格式化为十六进制的字符串,您需要这样的东西来将数字转换为十六进制QString

uint decimal = 255;
QString hexadecimal{};
hexadecimal.setNum(decimal,16);

最后,代码看起来像:

void InsnTable::insertInsn(const InsnEntry &insn)
{
this->insertRow(this->rowCount());
QTableWidgetItem *addrValue = new QTableWidgetItem();
uint64_t addr = insn.addr();
QString hexadecimal{};
hexadecimal.setNum(decimal,16);
addrValue->setData(Qt::EditRole, QVariant::fromValue(hexadecimal));
this->setItem(this->rowCount() - 1, 0, addrValue);
}

最新更新