Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Login screen (How to?)
QtWS25 Last Chance

Login screen (How to?)

Scheduled Pinned Locked Moved Unsolved General and Desktop
26 Posts 4 Posters 11.1k Views
  • 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.
  • cxamC Offline
    cxamC Offline
    cxam
    wrote on last edited by
    #1

    Hi! I designed my Qt Gui application using QtDesigner and in order to make diverse layers inside the application (login, main menu, settings, etc.) I made diverse QWidgets for each layer and depending which button inside the GUI was pressed the layers where showing or hiding... Now I have to make all this cool buttons functional and I have to make the login screen usable but I don't know how, in my login screen I have 4 elements: 1: the logo, 2&3: Username and Password QLineEdits and 4: The "Enter" button. I have to make all those funcitional.

    Thanks in advance:

    Carlos.

    Stay Hungry, Stay Foolish

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What are you going to validate your username/password ? Database ? Local file ?

      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
      0
      • cxamC Offline
        cxamC Offline
        cxam
        wrote on last edited by
        #3

        Just a string, the username and pasword wont be changed

        Stay Hungry, Stay Foolish

        kshegunovK 1 Reply Last reply
        0
        • cxamC cxam

          Just a string, the username and pasword wont be changed

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @cxam

          Just a string, the username and pasword wont be changed

          Just to put a note here - if you use a C++ string for the username and password suppose like this:

          const char * password = "my very secret password";
          

          No one can stop me (or anyone else) from loading your application/library in the disassembler and extracting that string. So do consider this, when thinking about passwords.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          2
          • cxamC Offline
            cxamC Offline
            cxam
            wrote on last edited by
            #5

            Yeah I know that it may not be really secure but I just want it to work the easiest way posible, anyways I still dont know how to make the username / password validation system

            Stay Hungry, Stay Foolish

            kshegunovK 1 Reply Last reply
            0
            • cxamC cxam

              Yeah I know that it may not be really secure but I just want it to work the easiest way posible, anyways I still dont know how to make the username / password validation system

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @cxam
              It's an ordinary dialog, is it not?

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0
              • cxamC Offline
                cxamC Offline
                cxam
                wrote on last edited by
                #7

                no, it's not the login takes places in the only window of the software: "mainwindow" when you enter the correct credentials then the login disappears and show the whole thing.

                Stay Hungry, Stay Foolish

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Well since it's only a very light login, put the logic in the widget and emit a signal when the login is successful. Then in your main window react on that signal and do the changes needed.

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

                  cxamC 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Well since it's only a very light login, put the logic in the widget and emit a signal when the login is successful. Then in your main window react on that signal and do the changes needed.

                    cxamC Offline
                    cxamC Offline
                    cxam
                    wrote on last edited by
                    #9

                    @SGaist I have, really little C++ knowledge, would you please tell me the code I have to add ? Thanks in advance

                    Stay Hungry, Stay Foolish

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Do you mean the comparison logic ?

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

                      cxamC 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Do you mean the comparison logic ?

                        cxamC Offline
                        cxamC Offline
                        cxam
                        wrote on last edited by
                        #11

                        @SGaist Yes.

                        Stay Hungry, Stay Foolish

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Something like

                          void MyLoginWidget::onOkButtonClicked() 
                          {
                              if (_usernameLineEdit->text() == MyValidUserName &&
                                  _passwordLineEdit->text() == MyTopSecretPassword) {
                                  emit loginSuccessful();
                              } else (
                                  QMessageBox::warning(this, tr("Error"), tr("Invalid username/password combination");
                                  _usernameLineEdit->clear();
                                  _passwordLineEdit->clear();
                              }
                          }
                          

                          WARNING: this is just a quick and dirty sample code.

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

                          cxamC 1 Reply Last reply
                          2
                          • SGaistS SGaist

                            Something like

                            void MyLoginWidget::onOkButtonClicked() 
                            {
                                if (_usernameLineEdit->text() == MyValidUserName &&
                                    _passwordLineEdit->text() == MyTopSecretPassword) {
                                    emit loginSuccessful();
                                } else (
                                    QMessageBox::warning(this, tr("Error"), tr("Invalid username/password combination");
                                    _usernameLineEdit->clear();
                                    _passwordLineEdit->clear();
                                }
                            }
                            

                            WARNING: this is just a quick and dirty sample code.

                            cxamC Offline
                            cxamC Offline
                            cxam
                            wrote on last edited by
                            #13

                            @SGaist So I have to add that code on "mainwindow.ccp" right ? (Sorry about my C++ knowledge haha)

                            Stay Hungry, Stay Foolish

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              No, in the login widget. The MainWindow widget should only react on the loginSuccessful signal.

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

                              cxamC 1 Reply Last reply
                              0
                              • SGaistS SGaist

                                No, in the login widget. The MainWindow widget should only react on the loginSuccessful signal.

                                cxamC Offline
                                cxamC Offline
                                cxam
                                wrote on last edited by
                                #15

                                @SGaist I hope this will show you more or less how I have my project structured: http://postimg.org/gallery/oeciyc12/660b7d39/

                                Stay Hungry, Stay Foolish

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  Ok… So you are trying to have everything in only once widget. Not a good idea. You should following the "Single Responsibility" paradigm. Create one widget per "complex" widget you will have in your main window. Otherwise you will end up with a monster class that does way to much things for its own good and yours to maintain.

                                  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
                                  0
                                  • cxamC Offline
                                    cxamC Offline
                                    cxam
                                    wrote on last edited by cxam
                                    #17

                                    @SGaist Yeah, I knew that my weird distribution would bring problems hahah. So I'll have to change it. Can you tell me which is the best distribution since I want that EVERYTHING happens in just one window (When I have the project finished I will embed it) ?

                                    Stay Hungry, Stay Foolish

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      Creating several widgets doesn't mean to you will have one application window per widget. What I'm suggesting is to separate things code-wise. You will still have only one MainWindow in the end containing everything but cleanly separated from a coding point of view.

                                      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
                                      0
                                      • cxamC Offline
                                        cxamC Offline
                                        cxam
                                        wrote on last edited by
                                        #19

                                        @SGaist Ok, I've created a new project > application > QtWidgets application then it created the "MainWindow" class, "MainWindow" header and "MainWindow" Ui.
                                        So for each "screen" I have to create a new C++ class ? Or... How? I don't understand the way to create widgets...

                                        Stay Hungry, Stay Foolish

                                        1 Reply Last reply
                                        0
                                        • SGaistS Offline
                                          SGaistS Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #20

                                          Yes, create a new C++ class. You will have the option to "pre-populate" it for design development. You should take the time to look at Qt Creator/Designer and Qt's tutorial about how to create UI with Designer.

                                          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
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved