How to create session and call it in QT
-
Hi,
So... Do you have any central database to store these details ?
Should it be only locally ?You have to give details about your application.
-
I managed to connect mongodb with QT and I recovered the data but the problem is when I closed the application the user will disconnect by default and when I open the application always the authentication interface is displayed.
So I want to save the user data locally from mongoDB so that it remains logged in -
I want to create session because I have list that I declare in the main using context property as following:
int main(int argc, char argv[])
{
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
qputenv("QT_QUICK_CONTROLS_STYLE", "material");
QGuiApplication app(argc, argv);
ApplicationUI appui;
QQmlApplicationEngine engine;
QQmlContext context = engine.rootContext();
context->setContextProperty("myApp", &appui);//Users list
QList<User*> listuser;
listuser=u.getallUser() ;
UserEntityModel modeluser;
for(int i =0;i<listuser.size();i++ )
{
QString fullname = listuser[i]->fullname();
QString email= listuser[i]->Email();
QString grade= listuser[i]->grade();
QString evaluation = listuser[i]->evaluation();
QString photo=listuser[i]->photo();
modeluser.addUserEntity(UserEntity(fullname,email,grade,evaluation,photo));
}
context->setContextProperty("userModel", &modeluser);
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
return app.exec();
}
For now I want to display the lists according to the logged user saved in session
But I can't refresh the list declared in the main, and it always shows me the lists of the last connection .
So I want to know how can refresh a list in real time. -
You should implement a class that does proper user management and updates the model as needed.
-
@SGaist please can you explain to me better, I didn't understand what I should to do!!!
And in QML I use the list model as following:
ListView {
id: listViewuser
anchors.bottomMargin: -3
anchors.leftMargin: -18
anchors.topMargin: -3
anchors.rightMargin: 5
focus: true
clip: true
anchors.fill: parent
model:userModel
delegate: userComponent
section.property: "sortGroup"
section.criteria: ViewSection.FullString
section.delegate: stateChanged
} -
Since it seems that your user may change while your application is running, you should have a class which goal is to handle user management and part of its job would be to update that list.