我正在显示一个包含一个blob(pdf文件)列的表。我可以隐藏用户的列,但是我想在列中显示一个文件时显示一个图标。我subclassed QsqlRealtionalTableModel并重载数据函数。如下所示。我的问题是,现在该图标与来自PDF的乱码数据一起显示。我认为这个超载函数正在代替数据的图标。QSqlRelationalTableModel显示一个图标而不是数据
QVariant RelationalTableModelWithIcon::data(const QModelIndex &item, int role) const
{
if(item.column() == 3 && role == Qt::DecorationRole)
{
QSqlRecord r= record(item.row());
QByteArray a= r.field(3).value().toByteArray();
QIcon icon = QIcon(":/icons/Art/Icons/Iynque-Flat-Ios7-Style-Documents-Pdf.ico");
if(a.isNull() == false)
{
return QVariant(icon);
}
}
return QSqlRelationalTableModel::data(item,role);
}
DROP TABLE IF EXISTS `ComOper`.`documentsqueue` ;
CREATE TABLE IF NOT EXISTS `ComOper`.`documentsqueue` (
`iddocumentsqueue` INT NOT NULL AUTO_INCREMENT,
`iddocument` INT NULL DEFAULT 1,
`name` VARCHAR(45) NOT NULL,
`image` MEDIUMBLOB NULL,
`dateEntered` DATE NULL,
`dateExpired` DATE NULL,
`dateApproved` DATE NULL,
`notes` MEDIUMTEXT NULL,
`archived` TINYINT NULL DEFAULT 0,
`iddocType` INT NOT NULL DEFAULT 1,
`idsupplier` INT NOT NULL,
`idfacilities` INT NOT NULL DEFAULT 1,
`idproducts` INT NOT NULL DEFAULT 1,
`iduser` INT NOT NULL DEFAULT 1,
PRIMARY KEY (`iddocumentsqueue`),
CONSTRAINT `fk_documentsqueue_docType1`
FOREIGN KEY (`iddocType`)
REFERENCES `ComOper`.`docType` (`iddocType`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documentsqueue_documents1`
FOREIGN KEY (`iddocument`)
REFERENCES `ComOper`.`documents` (`iddocument`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documentsqueue_user1`
FOREIGN KEY (`iduser`)
REFERENCES `ComOper`.`user` (`iduser`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documentsqueue_products1`
FOREIGN KEY (`idproducts`)
REFERENCES `ComOper`.`products` (`idproducts`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documentsqueue_facilities1`
FOREIGN KEY (`idfacilities`)
REFERENCES `ComOper`.`facilities` (`idfacilities`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_documentsqueue_supplier1`
FOREIGN KEY (`idsupplier`)
REFERENCES `ComOper`.`supplier` (`idsupplier`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
你可以共享数据库请测试你的代码,我想你正在使用sqlite作为数据库。 – eyllanesc
我从MySql工作台添加了create语句。 – Dan3460
其实这并没有什么帮助,我已经看到在你使用该数据库的几篇文章中,我建议在你想问的时候在sqlite中做一个测试数据库。 – eyllanesc