Login screen (How to?)
-
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.
-
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.
-
Do you mean the comparison logic ?
-
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.
-
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.
-
No, in the login widget. The MainWindow widget should only react on the loginSuccessful signal.
-
No, in the login widget. The MainWindow widget should only react on the loginSuccessful signal.
-
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.
-
@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) ?
-
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.
-
@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... -
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.
-
Looks like it but why do you have two different projects ?
-
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.
-
@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
-
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.pdfLook 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.