QStackedWidget: How to check if the next widget should be shown
-
A Signal must not have a definition, only a declaration.
The definition is made automatically in generated code by moc
wrote on 21 Nov 2019, 12:33 last edited by@J-Hilk alright, but how would I check if the login is correct if there's no function definition?
-
@J-Hilk alright, but how would I check if the login is correct if there's no function definition?
the idea would be, that you emit the signal, as soon as your function verifies, that the login was successful !
void LoginWidget::on_pushButton_clicked() { QString username = ui->lineEdit_2->text(); QString password = ui->lineEdit->text(); if(username == "Test" && password == "Test123") { emit loginSuccessful(); } }
-
@J-Hilk alright, but how would I check if the login is correct if there's no function definition?
wrote on 21 Nov 2019, 12:37 last edited by JonB@hobbyProgrammer
Subject to @J-Hilk suggesting an alternative, as I wrote earlier retain yourloginSuccesfull()
as the slot for the pushbutton click. Have itemit
a signal you define on successful validation of the widgets, the signal is a separate thing from your function which you must define as per the Qt/C++ rules.EDIT OK, @J-Hilk's code is the same thing, it's just that he has defined the pushbutton slot as
on_pushButton_clicked()
and the signal aslogInSuccessful
, so there is no longer any (non-signal) function namedloginSuccesfull()
. -
@hobbyProgrammer
Subject to @J-Hilk suggesting an alternative, as I wrote earlier retain yourloginSuccesfull()
as the slot for the pushbutton click. Have itemit
a signal you define on successful validation of the widgets, the signal is a separate thing from your function which you must define as per the Qt/C++ rules.EDIT OK, @J-Hilk's code is the same thing, it's just that he has defined the pushbutton slot as
on_pushButton_clicked()
and the signal aslogInSuccessful
, so there is no longer any (non-signal) function namedloginSuccesfull()
.wrote on 21 Nov 2019, 12:53 last edited by@JonB alright, so using that code and these lines:
LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0)); connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
should result in showApp to happen anytime the login was succesfull?
-
@JonB alright, so using that code and these lines:
LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0)); connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
should result in showApp to happen anytime the login was succesfull?
wrote on 21 Nov 2019, 13:04 last edited by@hobbyProgrammer
I'm hoping so! Did you try it? -
@hobbyProgrammer
I'm hoping so! Did you try it?wrote on 21 Nov 2019, 13:09 last edited by@JonB yes and it didn't work. I tried debugging but I can't seem to find what's going wrong. It hits the code where the emit loginSuccessfull() is set, but it doesn't go to the SLOT where it's connected to and it ends in :
while (!d->exit.loadAcquire()) processEvents(flags | WaitForMoreEvents | EventLoopExec);
-
@JonB yes and it didn't work. I tried debugging but I can't seem to find what's going wrong. It hits the code where the emit loginSuccessfull() is set, but it doesn't go to the SLOT where it's connected to and it ends in :
while (!d->exit.loadAcquire()) processEvents(flags | WaitForMoreEvents | EventLoopExec);
@hobbyProgrammer Did you make sure
connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
succeeded? And is this "login" the one you're actually showing?
-
@hobbyProgrammer Did you make sure
connect(login, SIGNAL(loginSuccesfull()), this, SLOT(showApp()));
succeeded? And is this "login" the one you're actually showing?
wrote on 21 Nov 2019, 13:18 last edited by@jsulm
it should be since I'm doing this:LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0));
-
@jsulm
it should be since I'm doing this:LoginWidget *login = qobject_cast<LoginWidget*>(ui->stackedWidget->widget(0));
@hobbyProgrammer And connect succeeded?
-
@hobbyProgrammer And connect succeeded?
wrote on 21 Nov 2019, 13:24 last edited by@jsulm I'm not sure, but I don't think so.
-
@jsulm I'm not sure, but I don't think so.
@hobbyProgrammer said in QStackedWidget: How to check if the next widget should be shown:
but I don't think so
Then it can't work.
Use new Qt5 connect syntax to be sure signal/slot are really connected:connect(login, &LoginWidget::loginSuccesfull, this, &MainWindow::showApp);
-
@hobbyProgrammer said in QStackedWidget: How to check if the next widget should be shown:
but I don't think so
Then it can't work.
Use new Qt5 connect syntax to be sure signal/slot are really connected:connect(login, &LoginWidget::loginSuccesfull, this, &MainWindow::showApp);
wrote on 21 Nov 2019, 13:27 last edited by@jsulm yes thank you. That worked!
Thank you so much for you patience and help.
-
Because this is getting out of hand:
22/25