QStandardItemModel from C++ not visisble in QtQuick / QML TableViewHow to subclass QStandardItemModel to use my own Item type?What are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhat is the effect of extern “C” in C++?Why do we need virtual functions in C++?Easiest way to convert int to string in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?Display QStandardItemModel in a QML TableViewPass QStandardItemModel from C++ to QtQuick / QML TableView and display it

What are these hats and the function of those wearing them? worn by the Russian imperial army at Borodino

Music Theory: Facts or Hierarchy of Opinions?

Can starter be used as an alternator?

How to structure presentation to avoid getting questions that will be answered later in the presentation?

Numerically Stable IIR filter

How to innovate in OR

Best Ergonomic Design for a handheld ranged weapon

Stationing Callouts using VBScript Labeling in ArcMap?

Is it unprofessional to mention your cover letter and resume are best viewed in Chrome?

When did J.K. Rowling decide to make Ron and Hermione a couple?

Password management for kids - what's a good way to start?

Should I put my name first or last in the team members list?

Should students have access to past exams or an exam bank?

Word for soundtrack music which is part of the action of the movie

Can I shorten this filter, that finds disk sizes over 100G?

Create and use Object Variable

What is the range of a Drunken Monk's Redirect attack?

Applications of pure mathematics in operations research

No Shirt, No Shoes, Service

Balancing Humanoid fantasy races: Elves

Adding a (stair/baby) gate without facing walls

Was Donald Trump at ground zero helping out on 9-11?

How is char processed in math mode?

What is the oxidation state of Mn in HMn(CO)5?



QStandardItemModel from C++ not visisble in QtQuick / QML TableView


How to subclass QStandardItemModel to use my own Item type?What are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhat is the effect of extern “C” in C++?Why do we need virtual functions in C++?Easiest way to convert int to string in C++C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?Display QStandardItemModel in a QML TableViewPass QStandardItemModel from C++ to QtQuick / QML TableView and display it






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have subclassed QStandardItemModel and want to link it with TableView in QML. But data from QStandardItemModel is not visible in TableView.



With role set to "display" in tableview I am able to see first column so I have re-implemented roleNames() function in my class but still no success.
I am not sure how to link roleNames enum with column in QStandardItemModel?



class AuditLogsModel : public QStandardItemModel
{
Q_OBJECT
QList<QStandardItem*> row;
public:
enum AuditRoles

DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
...

Implementation (C++) source

AuditLogsModel::AuditLogsModel(QObject *parent)
: QStandardItemModel(parent)

row.clear();
loadData();
setColumnMapping();


void AuditLogsModel::setColumnMapping()

setData(index(0,0), "DateTime", AuditRoles::DateTimeRole);
setData(index(0,1), "Name", AuditRoles::UsernameRole);
setData(index(0,2), "Application", AuditRoles::ApplicationRole);
setData(index(0,3), "Category", AuditRoles::CategoryRole);
setData(index(0,4), "Description", AuditRoles::DescriptionRole);


QHash<int, QByteArray> AuditLogsModel::roleNames() const

QHash<int, QByteArray> roleNameMap;
roleNameMap[DateTimeRole] = "DateTime";
roleNameMap[UsernameRole] = "Name";
roleNameMap[ApplicationRole] = "Application";
roleNameMap[CategoryRole] = "Category";
roleNameMap[DescriptionRole] = "Description";

return roleNameMap;


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if( file.exists() == false )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);

QString line;
QJsonObject logEntry;
while(!in.atEnd())

line = in.readLine();
logEntry = (QJsonDocument::fromJson(line.toStdString().c_str())).object();

row.append(new QStandardItem(logEntry["Date-time"].toString()));
row.append(new QStandardItem(logEntry["username"].toString()));
row.append(new QStandardItem(logEntry["App_name"].toString()));
row.append(new QStandardItem(logEntry["event_category"].toString()));
row.append(new QStandardItem(logEntry["event_desc"].toString()));

appendRow(row);
row.clear();

file.close();





QML code



 TableView 
id: auditLogTable
[geometry]
model: auditLogModelObj

TableViewColumn
role: "DateTime"
title: qsTr("Local Time")
width: auditLogTable.width * 0.15


TableViewColumn
role: "Name"
title: qsTr("Created By")
width: auditLogTable.width * 0.1


TableViewColumn
role: "Application"
title: qsTr("app name")
width: auditLogTable.width * 0.40


TableViewColumn
role: "Category"
title: qsTr("Category")
width: auditLogTable.width * 0.2


TableViewColumn
role: "Description"
title: qsTr("Detail")
width: auditLogTable.width * 0.40











share|improve this question
























  • where's your AuditLogsModel::setData() method? check this out: stackoverflow.com/questions/17050573/…

    – bardao
    Mar 26 at 22:49


















1















I have subclassed QStandardItemModel and want to link it with TableView in QML. But data from QStandardItemModel is not visible in TableView.



With role set to "display" in tableview I am able to see first column so I have re-implemented roleNames() function in my class but still no success.
I am not sure how to link roleNames enum with column in QStandardItemModel?



class AuditLogsModel : public QStandardItemModel
{
Q_OBJECT
QList<QStandardItem*> row;
public:
enum AuditRoles

DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
...

Implementation (C++) source

AuditLogsModel::AuditLogsModel(QObject *parent)
: QStandardItemModel(parent)

row.clear();
loadData();
setColumnMapping();


void AuditLogsModel::setColumnMapping()

setData(index(0,0), "DateTime", AuditRoles::DateTimeRole);
setData(index(0,1), "Name", AuditRoles::UsernameRole);
setData(index(0,2), "Application", AuditRoles::ApplicationRole);
setData(index(0,3), "Category", AuditRoles::CategoryRole);
setData(index(0,4), "Description", AuditRoles::DescriptionRole);


QHash<int, QByteArray> AuditLogsModel::roleNames() const

QHash<int, QByteArray> roleNameMap;
roleNameMap[DateTimeRole] = "DateTime";
roleNameMap[UsernameRole] = "Name";
roleNameMap[ApplicationRole] = "Application";
roleNameMap[CategoryRole] = "Category";
roleNameMap[DescriptionRole] = "Description";

return roleNameMap;


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if( file.exists() == false )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);

QString line;
QJsonObject logEntry;
while(!in.atEnd())

line = in.readLine();
logEntry = (QJsonDocument::fromJson(line.toStdString().c_str())).object();

row.append(new QStandardItem(logEntry["Date-time"].toString()));
row.append(new QStandardItem(logEntry["username"].toString()));
row.append(new QStandardItem(logEntry["App_name"].toString()));
row.append(new QStandardItem(logEntry["event_category"].toString()));
row.append(new QStandardItem(logEntry["event_desc"].toString()));

appendRow(row);
row.clear();

file.close();





QML code



 TableView 
id: auditLogTable
[geometry]
model: auditLogModelObj

TableViewColumn
role: "DateTime"
title: qsTr("Local Time")
width: auditLogTable.width * 0.15


TableViewColumn
role: "Name"
title: qsTr("Created By")
width: auditLogTable.width * 0.1


TableViewColumn
role: "Application"
title: qsTr("app name")
width: auditLogTable.width * 0.40


TableViewColumn
role: "Category"
title: qsTr("Category")
width: auditLogTable.width * 0.2


TableViewColumn
role: "Description"
title: qsTr("Detail")
width: auditLogTable.width * 0.40











share|improve this question
























  • where's your AuditLogsModel::setData() method? check this out: stackoverflow.com/questions/17050573/…

    – bardao
    Mar 26 at 22:49














1












1








1








I have subclassed QStandardItemModel and want to link it with TableView in QML. But data from QStandardItemModel is not visible in TableView.



With role set to "display" in tableview I am able to see first column so I have re-implemented roleNames() function in my class but still no success.
I am not sure how to link roleNames enum with column in QStandardItemModel?



class AuditLogsModel : public QStandardItemModel
{
Q_OBJECT
QList<QStandardItem*> row;
public:
enum AuditRoles

DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
...

Implementation (C++) source

AuditLogsModel::AuditLogsModel(QObject *parent)
: QStandardItemModel(parent)

row.clear();
loadData();
setColumnMapping();


void AuditLogsModel::setColumnMapping()

setData(index(0,0), "DateTime", AuditRoles::DateTimeRole);
setData(index(0,1), "Name", AuditRoles::UsernameRole);
setData(index(0,2), "Application", AuditRoles::ApplicationRole);
setData(index(0,3), "Category", AuditRoles::CategoryRole);
setData(index(0,4), "Description", AuditRoles::DescriptionRole);


QHash<int, QByteArray> AuditLogsModel::roleNames() const

QHash<int, QByteArray> roleNameMap;
roleNameMap[DateTimeRole] = "DateTime";
roleNameMap[UsernameRole] = "Name";
roleNameMap[ApplicationRole] = "Application";
roleNameMap[CategoryRole] = "Category";
roleNameMap[DescriptionRole] = "Description";

return roleNameMap;


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if( file.exists() == false )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);

QString line;
QJsonObject logEntry;
while(!in.atEnd())

line = in.readLine();
logEntry = (QJsonDocument::fromJson(line.toStdString().c_str())).object();

row.append(new QStandardItem(logEntry["Date-time"].toString()));
row.append(new QStandardItem(logEntry["username"].toString()));
row.append(new QStandardItem(logEntry["App_name"].toString()));
row.append(new QStandardItem(logEntry["event_category"].toString()));
row.append(new QStandardItem(logEntry["event_desc"].toString()));

appendRow(row);
row.clear();

file.close();





QML code



 TableView 
id: auditLogTable
[geometry]
model: auditLogModelObj

TableViewColumn
role: "DateTime"
title: qsTr("Local Time")
width: auditLogTable.width * 0.15


TableViewColumn
role: "Name"
title: qsTr("Created By")
width: auditLogTable.width * 0.1


TableViewColumn
role: "Application"
title: qsTr("app name")
width: auditLogTable.width * 0.40


TableViewColumn
role: "Category"
title: qsTr("Category")
width: auditLogTable.width * 0.2


TableViewColumn
role: "Description"
title: qsTr("Detail")
width: auditLogTable.width * 0.40











share|improve this question














I have subclassed QStandardItemModel and want to link it with TableView in QML. But data from QStandardItemModel is not visible in TableView.



With role set to "display" in tableview I am able to see first column so I have re-implemented roleNames() function in my class but still no success.
I am not sure how to link roleNames enum with column in QStandardItemModel?



class AuditLogsModel : public QStandardItemModel
{
Q_OBJECT
QList<QStandardItem*> row;
public:
enum AuditRoles

DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
...

Implementation (C++) source

AuditLogsModel::AuditLogsModel(QObject *parent)
: QStandardItemModel(parent)

row.clear();
loadData();
setColumnMapping();


void AuditLogsModel::setColumnMapping()

setData(index(0,0), "DateTime", AuditRoles::DateTimeRole);
setData(index(0,1), "Name", AuditRoles::UsernameRole);
setData(index(0,2), "Application", AuditRoles::ApplicationRole);
setData(index(0,3), "Category", AuditRoles::CategoryRole);
setData(index(0,4), "Description", AuditRoles::DescriptionRole);


QHash<int, QByteArray> AuditLogsModel::roleNames() const

QHash<int, QByteArray> roleNameMap;
roleNameMap[DateTimeRole] = "DateTime";
roleNameMap[UsernameRole] = "Name";
roleNameMap[ApplicationRole] = "Application";
roleNameMap[CategoryRole] = "Category";
roleNameMap[DescriptionRole] = "Description";

return roleNameMap;


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if( file.exists() == false )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);

QString line;
QJsonObject logEntry;
while(!in.atEnd())

line = in.readLine();
logEntry = (QJsonDocument::fromJson(line.toStdString().c_str())).object();

row.append(new QStandardItem(logEntry["Date-time"].toString()));
row.append(new QStandardItem(logEntry["username"].toString()));
row.append(new QStandardItem(logEntry["App_name"].toString()));
row.append(new QStandardItem(logEntry["event_category"].toString()));
row.append(new QStandardItem(logEntry["event_desc"].toString()));

appendRow(row);
row.clear();

file.close();





QML code



 TableView 
id: auditLogTable
[geometry]
model: auditLogModelObj

TableViewColumn
role: "DateTime"
title: qsTr("Local Time")
width: auditLogTable.width * 0.15


TableViewColumn
role: "Name"
title: qsTr("Created By")
width: auditLogTable.width * 0.1


TableViewColumn
role: "Application"
title: qsTr("app name")
width: auditLogTable.width * 0.40


TableViewColumn
role: "Category"
title: qsTr("Category")
width: auditLogTable.width * 0.2


TableViewColumn
role: "Description"
title: qsTr("Detail")
width: auditLogTable.width * 0.40








c++ qt qml tableview qt-quick






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 22:43









user746184user746184

601 silver badge9 bronze badges




601 silver badge9 bronze badges















  • where's your AuditLogsModel::setData() method? check this out: stackoverflow.com/questions/17050573/…

    – bardao
    Mar 26 at 22:49


















  • where's your AuditLogsModel::setData() method? check this out: stackoverflow.com/questions/17050573/…

    – bardao
    Mar 26 at 22:49

















where's your AuditLogsModel::setData() method? check this out: stackoverflow.com/questions/17050573/…

– bardao
Mar 26 at 22:49






where's your AuditLogsModel::setData() method? check this out: stackoverflow.com/questions/17050573/…

– bardao
Mar 26 at 22:49













1 Answer
1






active

oldest

votes


















1














I do not understand what you tried to do in setColumnMapping(), and you do not need to use roleNames() either. In addition, the TableView that you use only accepts model of list type, in this case the roles will be the columns, considering that the solution is:



*.h



class AuditLogsModel : public QStandardItemModel

public:
enum AuditRoles
DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
AuditLogsModel(QObject *parent=nullptr);
void loadData();
;


*.cpp



AuditLogsModel::AuditLogsModel(QObject *parent):
QStandardItemModel(parent)

QHash<int, QByteArray> roles;
roles[DateTimeRole] = "DateTime";
roles[UsernameRole] = "Name";
roles[ApplicationRole] = "Application";
roles[CategoryRole] = "Category";
roles[DescriptionRole] = "Description";
setItemRoleNames(roles);


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if(!file.exists() )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);
QString line;
QJsonObject logEntry;
while(!in.atEnd())
QStandardItem *row = new QStandardItem;
line = in.readLine();
logEntry = (QJsonDocument::fromJson (line.toStdString().c_str())).object();
row->setData(logEntry["Date-time"].toString(), DateTimeRole);
row->setData(logEntry["username"].toString(), UsernameRole);
row->setData(logEntry["App_name"].toString(), ApplicationRole);
row->setData(logEntry["event_category"].toString(), CategoryRole);
row->setData(logEntry["event_desc"].toString(), DescriptionRole);
appendRow(row);

file.close();







share|improve this answer

























  • Thanks a lot !! It worked.

    – user746184
    Mar 27 at 15:09











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367232%2fqstandarditemmodel-from-c-not-visisble-in-qtquick-qml-tableview%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I do not understand what you tried to do in setColumnMapping(), and you do not need to use roleNames() either. In addition, the TableView that you use only accepts model of list type, in this case the roles will be the columns, considering that the solution is:



*.h



class AuditLogsModel : public QStandardItemModel

public:
enum AuditRoles
DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
AuditLogsModel(QObject *parent=nullptr);
void loadData();
;


*.cpp



AuditLogsModel::AuditLogsModel(QObject *parent):
QStandardItemModel(parent)

QHash<int, QByteArray> roles;
roles[DateTimeRole] = "DateTime";
roles[UsernameRole] = "Name";
roles[ApplicationRole] = "Application";
roles[CategoryRole] = "Category";
roles[DescriptionRole] = "Description";
setItemRoleNames(roles);


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if(!file.exists() )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);
QString line;
QJsonObject logEntry;
while(!in.atEnd())
QStandardItem *row = new QStandardItem;
line = in.readLine();
logEntry = (QJsonDocument::fromJson (line.toStdString().c_str())).object();
row->setData(logEntry["Date-time"].toString(), DateTimeRole);
row->setData(logEntry["username"].toString(), UsernameRole);
row->setData(logEntry["App_name"].toString(), ApplicationRole);
row->setData(logEntry["event_category"].toString(), CategoryRole);
row->setData(logEntry["event_desc"].toString(), DescriptionRole);
appendRow(row);

file.close();







share|improve this answer

























  • Thanks a lot !! It worked.

    – user746184
    Mar 27 at 15:09
















1














I do not understand what you tried to do in setColumnMapping(), and you do not need to use roleNames() either. In addition, the TableView that you use only accepts model of list type, in this case the roles will be the columns, considering that the solution is:



*.h



class AuditLogsModel : public QStandardItemModel

public:
enum AuditRoles
DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
AuditLogsModel(QObject *parent=nullptr);
void loadData();
;


*.cpp



AuditLogsModel::AuditLogsModel(QObject *parent):
QStandardItemModel(parent)

QHash<int, QByteArray> roles;
roles[DateTimeRole] = "DateTime";
roles[UsernameRole] = "Name";
roles[ApplicationRole] = "Application";
roles[CategoryRole] = "Category";
roles[DescriptionRole] = "Description";
setItemRoleNames(roles);


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if(!file.exists() )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);
QString line;
QJsonObject logEntry;
while(!in.atEnd())
QStandardItem *row = new QStandardItem;
line = in.readLine();
logEntry = (QJsonDocument::fromJson (line.toStdString().c_str())).object();
row->setData(logEntry["Date-time"].toString(), DateTimeRole);
row->setData(logEntry["username"].toString(), UsernameRole);
row->setData(logEntry["App_name"].toString(), ApplicationRole);
row->setData(logEntry["event_category"].toString(), CategoryRole);
row->setData(logEntry["event_desc"].toString(), DescriptionRole);
appendRow(row);

file.close();







share|improve this answer

























  • Thanks a lot !! It worked.

    – user746184
    Mar 27 at 15:09














1












1








1







I do not understand what you tried to do in setColumnMapping(), and you do not need to use roleNames() either. In addition, the TableView that you use only accepts model of list type, in this case the roles will be the columns, considering that the solution is:



*.h



class AuditLogsModel : public QStandardItemModel

public:
enum AuditRoles
DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
AuditLogsModel(QObject *parent=nullptr);
void loadData();
;


*.cpp



AuditLogsModel::AuditLogsModel(QObject *parent):
QStandardItemModel(parent)

QHash<int, QByteArray> roles;
roles[DateTimeRole] = "DateTime";
roles[UsernameRole] = "Name";
roles[ApplicationRole] = "Application";
roles[CategoryRole] = "Category";
roles[DescriptionRole] = "Description";
setItemRoleNames(roles);


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if(!file.exists() )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);
QString line;
QJsonObject logEntry;
while(!in.atEnd())
QStandardItem *row = new QStandardItem;
line = in.readLine();
logEntry = (QJsonDocument::fromJson (line.toStdString().c_str())).object();
row->setData(logEntry["Date-time"].toString(), DateTimeRole);
row->setData(logEntry["username"].toString(), UsernameRole);
row->setData(logEntry["App_name"].toString(), ApplicationRole);
row->setData(logEntry["event_category"].toString(), CategoryRole);
row->setData(logEntry["event_desc"].toString(), DescriptionRole);
appendRow(row);

file.close();







share|improve this answer













I do not understand what you tried to do in setColumnMapping(), and you do not need to use roleNames() either. In addition, the TableView that you use only accepts model of list type, in this case the roles will be the columns, considering that the solution is:



*.h



class AuditLogsModel : public QStandardItemModel

public:
enum AuditRoles
DateTimeRole = Qt::UserRole + 1,
UsernameRole,
ApplicationRole,
CategoryRole,
DescriptionRole
;
AuditLogsModel(QObject *parent=nullptr);
void loadData();
;


*.cpp



AuditLogsModel::AuditLogsModel(QObject *parent):
QStandardItemModel(parent)

QHash<int, QByteArray> roles;
roles[DateTimeRole] = "DateTime";
roles[UsernameRole] = "Name";
roles[ApplicationRole] = "Application";
roles[CategoryRole] = "Category";
roles[DescriptionRole] = "Description";
setItemRoleNames(roles);


void AuditLogsModel::loadData()

QFile file(AUDIT_LOG_PATH);
if(!file.exists() )

syslog(LOG_ERR,qPrintable(QString("Audit log file: %1 does not exist").arg(AUDIT_LOG_PATH)));
return;


if (file.open(QIODevice::ReadOnly))

QTextStream in(&file);
QString line;
QJsonObject logEntry;
while(!in.atEnd())
QStandardItem *row = new QStandardItem;
line = in.readLine();
logEntry = (QJsonDocument::fromJson (line.toStdString().c_str())).object();
row->setData(logEntry["Date-time"].toString(), DateTimeRole);
row->setData(logEntry["username"].toString(), UsernameRole);
row->setData(logEntry["App_name"].toString(), ApplicationRole);
row->setData(logEntry["event_category"].toString(), CategoryRole);
row->setData(logEntry["event_desc"].toString(), DescriptionRole);
appendRow(row);

file.close();








share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 23:34









eyllanesceyllanesc

104k12 gold badges38 silver badges70 bronze badges




104k12 gold badges38 silver badges70 bronze badges















  • Thanks a lot !! It worked.

    – user746184
    Mar 27 at 15:09


















  • Thanks a lot !! It worked.

    – user746184
    Mar 27 at 15:09

















Thanks a lot !! It worked.

– user746184
Mar 27 at 15:09






Thanks a lot !! It worked.

– user746184
Mar 27 at 15:09









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367232%2fqstandarditemmodel-from-c-not-visisble-in-qtquick-qml-tableview%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현