Okay I see why QML wasn’t loading I wasnt calling it to load lol
used my engine object and pass it the qml file to load.
QQmlApplicationEngine engine;
QQmlContext *contxt = engine.rootContext();
contxt->setContextProperty("sqliteModel", model);
engine.
load(QUrl(QStringLiteral
("qrc:/main.qml")));
return app.exec();
QQmlApplicationEngine engine;
QQmlContext *contxt = engine.rootContext();
contxt->setContextProperty("sqliteModel", model);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
To copy to clipboard, switch view to plain text mode
app complies further along
debug statements:
QML debugging is enabled. Only use this in a safe environment.
connected to DB
sql statement exicuted fine
made it inside addEvent 1
made it inside addEvent 2
made it inside addEvent 1
made it inside addEvent 2
QHash((478,
"eventMessage")(479,
"dateTime")(476,
"id")(477,
"userName")) ASSERT failure in QList<T>::at: "index out of range", file /opt/qt55/include/QtCore/qlist.h, line 510
QML debugging is enabled. Only use this in a safe environment.
connected to DB
sql statement exicuted fine
made it inside addEvent 1
made it inside addEvent 2
made it inside addEvent 1
made it inside addEvent 2
QHash((478, "eventMessage")(479, "dateTime")(476, "id")(477, "userName"))
QVariant(QString, "2")
QVariant(QString, "2")
QVariant(QString, "")
QVariant(QString, "")
ASSERT failure in QList<T>::at: "index out of range", file /opt/qt55/include/QtCore/qlist.h, line 510
To copy to clipboard, switch view to plain text mode
However I'm running into and issue with my QList (index out of range) is it not declaring memory space for the list? QList should create memory location on the Heap automatically right?
update: thought it might be my insert() function call but after running through the debugger it looks like getting error from: Signal: SIGABRT
userEventLogMsg msg = m_msgList.at(0);
userEventLogMsg msg = m_msgList.at(0);
To copy to clipboard, switch view to plain text mode
Added after 5 minutes:
"Leaking means that memory is lost.
You are allocating userEventLogMsg objects on the heap (using new) but not releasing that memory with delete anywhere."
I might be getting the two confused but doesn’t the heap de-allocate memory for you? or is that the memory on the stack?
I removed the new declaration from my msg userEventLogMsg obj
while (myQuery.next()){
userEventLogMsg msg;
QString myString
= myQuery.
value(0).
toString();
msg.id.insert(0, myString);
model->addEvent(msg);
}
while (myQuery.next()){
userEventLogMsg msg;
QString myString = myQuery.value(0).toString();
msg.id.insert(0, myString);
model->addEvent(msg);
}
To copy to clipboard, switch view to plain text mode
"You are using hardcoded numbers to access which message you are getting the data from instead of using the row information of the index argument."
How would I do this? little confused sorry (update: use the index row from message list)
Updated code:
{
if (index.row() < 0 || index.row() >= m_msgList.count())
{
}
if(role == idRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.id;
qDebug() << text;
}
else if(role == nameRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.username;
qDebug() << text;
}
else if(role == msgRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.eventmessage;
qDebug() << text;
}
if(role == dateRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.datetime.toLocalTime().toString("M'/'d'/'yyyy' 'h:mm:ss ap" );
qDebug() << text;
}
return text;
}
}
//While loop form main.cpp
while (myQuery.next()){
userEventLogMsg msg;
QString idString
= myQuery.
value(0).
toString();
msg.id.insert(0, idString);
QString userString
= myQuery.
value(3).
toString();
msg.username.insert(1, userString);
QString eventString
= myQuery.
value(4).
toString();
msg.eventmessage.insert(2, eventString);
QString dateString
= myQuery.
value(5).
toString();
msg.datetime.insert(3, dateString);
model->addEvent(msg);
}
QVariant sqliteModel::data(const QModelIndex &index, int role) const
{
if (index.row() < 0 || index.row() >= m_msgList.count())
{
return QVariant();
}
QVariant text;
if(role == idRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.id;
qDebug() << text;
}
else if(role == nameRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.username;
qDebug() << text;
}
else if(role == msgRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.eventmessage;
qDebug() << text;
}
if(role == dateRole)
{
userEventLogMsg msg = m_msgList[index.row()];
text = msg.datetime.toLocalTime().toString("M'/'d'/'yyyy' 'h:mm:ss ap" );
qDebug() << text;
}
return text;
}
}
//While loop form main.cpp
while (myQuery.next()){
userEventLogMsg msg;
QString idString = myQuery.value(0).toString();
msg.id.insert(0, idString);
QString userString = myQuery.value(3).toString();
msg.username.insert(1, userString);
QString eventString = myQuery.value(4).toString();
msg.eventmessage.insert(2, eventString);
QString dateString = myQuery.value(5).toString();
msg.datetime.insert(3, dateString);
model->addEvent(msg);
}
To copy to clipboard, switch view to plain text mode
update: Have an issue trying to insert() my datetime (error QDateTime has no member named insert) what other function call can i use to get datetime data into the struct var?
update: changed datetime data Type from QDateTime to QString. (date is formatted in database no need for QdateTime?)
update: Ran through debugger set break point at
return exec()
return exec()
To copy to clipboard, switch view to plain text mode
in main.cpp, and break point at
model: sqliteModel
model: sqliteModel
To copy to clipboard, switch view to plain text mode
segmentation fault (SIGSEGV) when model is called in QML?
model: sqliteModel
model: sqliteModel
To copy to clipboard, switch view to plain text mode
my Model declaration is one of two pointers I use so far in this app
sqliteModel *model = new sqliteModel;
QmlContext *contxt = engine.rootContext();
sqliteModel *model = new sqliteModel;
QmlContext *contxt = engine.rootContext();
To copy to clipboard, switch view to plain text mode
How do I manage the model pointer not to cause a seg fault ? How do I properly call/pass the C++ model to QML ?
//---/ Display Rows from database in tableView /---//
Window
{
ListView
{
width: 600; height: 250
//---/ C++ model set using context property in main.cpp /---//
model: sqliteModel
//---// items are drawn by a delegate. /---//
delegate: Text { text: "Record: " + id + ", " + userName + ", " + eventMessage + ", " + dateTime}
}
}
//---/ Display Rows from database in tableView /---//
Window
{
ListView
{
width: 600; height: 250
//---/ C++ model set using context property in main.cpp /---//
model: sqliteModel
//---// items are drawn by a delegate. /---//
delegate: Text { text: "Record: " + id + ", " + userName + ", " + eventMessage + ", " + dateTime}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks