How to create session and call it in QT
-
wrote on 30 May 2017, 09:12 last edited by
Hi, please how can I create a session and call it in QT!!
-
wrote on 30 May 2017, 10:02 last edited by
Hi jiji,
Could you be more specific about your question?
What kind of session are you talking about?Eddy
-
wrote on 30 May 2017, 10:55 last edited by
I want to store my user credentials, so I got to use a session
-
wrote on 30 May 2017, 11:59 last edited by
Is it to access a database, a network, your own app that you want to protect?
Please tell us more about your use case.
-
wrote on 30 May 2017, 12:33 last edited by jiji
In my application I have to manage user , so every time after authenticating I want to store the user details in a place that is easy to access.
-
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.
-
wrote on 31 May 2017, 07:59 last edited by
Hi,
I store my data base in a mongoDB server, and I want to store user details locally, because when I close the application the user disconnect, but I want it remain connected. -
wrote on 31 May 2017, 08:40 last edited by
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 -
@Eddy I'd avoid plain QSettings for that, the credentials would be stored in plain text. Credentials are sensitive information that should be encrypted.
-
wrote on 31 May 2017, 11:14 last edited by
In the main method I use : engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); to display the authentification. So where I should put Qsettings!!??
-
wrote on 31 May 2017, 12:48 last edited by
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.
-
wrote on 31 May 2017, 23:42 last edited by jiji
@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.
8/18