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?)

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

                              @SGaist So... http://postimg.org/image/7djf0eb6v/ like this?

                              Stay Hungry, Stay Foolish

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

                                Looks like it but why do you have two different projects ?

                                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
                                1
                                • SGaistS SGaist

                                  Looks like it but why do you have two different projects ?

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

                                  @SGaist I'm sorry, The first one is the old one and the second one is the new one. Ok now I think I understand how it works hahah, thanks for your help. Let's see if I can learn how Qt works. By the way... Do you know any good tutorial for qt ?

                                  Stay Hungry, Stay Foolish

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

                                    Well, you can start by looking at Qt's own documentation for tutorials. Since you are using Designer it also has a nice documentation to help you get started.

                                    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
                                      #25

                                      @SGaist Well, I did start from there but I found it too complicated I mean, the documentation seems that is the place where you go to double check things or to search a certain thing but I need something more like a guide or a book or something like that hahah

                                      Stay Hungry, Stay Foolish

                                      1 Reply Last reply
                                      0
                                      • mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by mrjj
                                        #26

                                        Hi
                                        I find this book good for inspiration on how classes fits together.
                                        http://www.bogotobogo.com/cplusplus/files/c-gui-programming-with-qt-4-2ndedition.pdf

                                        Look for "Signals and Slots in Depth".

                                        This is for Qt4 and its important to know that you can make use of Designers ability to
                                        auto connect instead of code as shown in book.

                                        Right click and select Goto Slot. Then choose released() .
                                        It will then create a function (slot) for you that will be called when button is pressed and released.
                                        The name is important so no rename. (for auto connect to work)

                                        Also, there many good videos on youtube for how to use Designer.

                                        1 Reply Last reply
                                        3

                                        • Login

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