Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved How to create session and call it in QT

    QML and Qt Quick
    3
    18
    3631
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jiji last edited by

      Hi, please how can I create a session and call it in QT!!

      1 Reply Last reply Reply Quote 0
      • E
        Eddy last edited by

        Hi jiji,

        Could you be more specific about your question?
        What kind of session are you talking about?

        Eddy

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply Reply Quote 1
        • J
          jiji last edited by

          I want to store my user credentials, so I got to use a session

          1 Reply Last reply Reply Quote 0
          • E
            Eddy 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.

            Qt Certified Specialist
            www.edalsolutions.be

            1 Reply Last reply Reply Quote 1
            • J
              jiji 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.

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 2
                • J
                  jiji 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.

                  1 Reply Last reply Reply Quote 0
                  • E
                    Eddy last edited by

                    Hi,

                    This topic might have links to sample code you need.

                    You could also search for other posts of course.

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply Reply Quote 1
                    • J
                      jiji 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

                      1 Reply Last reply Reply Quote 0
                      • E
                        Eddy last edited by

                        You could store the user data in Qsettings. When opening the db check if there is a username filled in already.
                        If it is don't show the authentification display but use the credentials from Qsettings.

                        Qt Certified Specialist
                        www.edalsolutions.be

                        1 Reply Last reply Reply Quote 1
                        • SGaist
                          SGaist Lifetime Qt Champion last edited by

                          @Eddy I'd avoid plain QSettings for that, the credentials would be stored in plain text. Credentials are sensitive information that should be encrypted.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply Reply Quote 1
                          • E
                            Eddy last edited by

                            @SGaist Yes, you're right, my bad.

                            It depends how strict the teacher will be for this school assignment ;-)

                            Qt Certified Specialist
                            www.edalsolutions.be

                            1 Reply Last reply Reply Quote 0
                            • J
                              jiji 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!!??

                              1 Reply Last reply Reply Quote 0
                              • E
                                Eddy last edited by

                                In the main method I use : engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
                                

                                Thanks for letting us know you are using QML...

                                Have a look at this link if you are not concerned with encryption yet.

                                Qt Certified Specialist
                                www.edalsolutions.be

                                1 Reply Last reply Reply Quote 0
                                • J
                                  jiji 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.

                                  1 Reply Last reply Reply Quote 0
                                  • SGaist
                                    SGaist Lifetime Qt Champion last edited by

                                    You should implement a class that does proper user management and updates the model as needed.

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply Reply Quote 0
                                    • J
                                      jiji 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
                                      }

                                      1 Reply Last reply Reply Quote 0
                                      • SGaist
                                        SGaist Lifetime Qt Champion last edited by

                                        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.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply Reply Quote 0
                                        • First post
                                          Last post