Unsolved Login screen (How to?)
-
@cxam
It's an ordinary dialog, is it not? -
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.
-
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.
-
@SGaist I have, really little C++ knowledge, would you please tell me the code I have to add ? Thanks in advance
-
Do you mean the comparison logic ?
-
@SGaist Yes.
-
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.
-
@SGaist So I have to add that code on "mainwindow.ccp" right ? (Sorry about my C++ knowledge haha)
-
No, in the login widget. The MainWindow widget should only react on the loginSuccessful signal.
-
@SGaist I hope this will show you more or less how I have my project structured: http://postimg.org/gallery/oeciyc12/660b7d39/
-
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.
-
@SGaist So... http://postimg.org/image/7djf0eb6v/ like this?
-
Looks like it but why do you have two different projects ?
-
@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 ?
-
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