4 Attachment(s)
open a window according to the type chosen in mainwindow
Hello
I work on an application under qt 5,
The user must first choose whether it is a doctor or patient or administrator
Attachment 12261
After another window will be opened to connect or register
Attachment 12262
If it clicks on join I want another window will be opened but depending on the type of user.
Attachment 12259
Attachment 12260
So please what can I do to I open a window according to the type chosen in mainwindow
Re: open a window according to the type chosen in mainwindow
C++ offers two language constructs to execute different code depending on some condition or value
The "if-else" statement https://en.wikipedia.org/wiki/Condit...2.80.93else.29
And the "switch" statement https://en.wikipedia.org/wiki/Switch_statement
You can likely find some C++ tutorials online to learn how to use these.
Cheers,
_
1 Attachment(s)
Re: open a window according to the type chosen in mainwindow
Good evening,
Thank you for your help :)
But when I use if and else if an error appears when compiling the program
C:\Users\LENOVO\Desktop\projet c++\code-sql\smart health v1\smart_health\mainwindow.h:26: error: 'void MainWindow::on_pushButton_3_clicked()' cannot be overloaded
void on_pushButton_3_clicked();
^
and an other :
C:\Users\LENOVO\Desktop\projet c++\code-sql\smart health v1\smart_health\mainwindow.h:19: error: with 'bool MainWindow::on_pushButton_3_clicked()'
bool on_pushButton_3_clicked();
^
This is because the on_pushButton_3_clicked () function is private and type void not bool.
Here is my mainwindow.h
Attachment 12263
Re: open a window according to the type chosen in mainwindow
I think anda_skoa means something like this:
Code:
// pseudocode
void MainWindow::on_pushButton_3_clicked()
{
switch ( userType )
{
case User:
showUserWindow();
break;
case Doctor:
showDoctorWindow();
break;
case Administrator:
showAdminWindow();
break;
default:
// error - no such user type
break;
}
}
Obviously, your code will store the "userType" based on the previous button the user clicked.
By the way, "pushButton_3" is a pretty bad name for a variable. A year from now, when you have to fix something in this code, will you remember which GUI button is the one named "pushButton_3" in the code? You'd probably have a much easier job if it were named "connectButton" or "joinButton" instead.
Re: open a window according to the type chosen in mainwindow
Quote:
Originally Posted by
rahma_sassi
C:\Users\LENOVO\Desktop\projet c++\code-sql\smart health v1\smart_health\mainwindow.h:26: error: 'void MainWindow::on_pushButton_3_clicked()' cannot be overloaded
void on_pushButton_3_clicked();
^
and an other :
C:\Users\LENOVO\Desktop\projet c++\code-sql\smart health v1\smart_health\mainwindow.h:19: error: with 'bool MainWindow::on_pushButton_3_clicked()'
bool on_pushButton_3_clicked();
^
This is because the on_pushButton_3_clicked () function is private and type void not bool.
You have two functions with the same name, in C++ that's called an overload.
Overloaded functions need to have different arguments, different return type is not enough.
I would suggest you look into a basic C++ tutorial first before continuting.
Cheers,
_