PDA

View Full Version : open a window according to the type chosen in mainwindow



rahma_sassi
23rd December 2016, 17:47
Hello
I work on an application under qt 5,
The user must first choose whether it is a doctor or patient or administrator
12261
After another window will be opened to connect or register
12262
If it clicks on join I want another window will be opened but depending on the type of user.
12259
12260


So please what can I do to I open a window according to the type chosen in mainwindow

anda_skoa
23rd December 2016, 18:34
C++ offers two language constructs to execute different code depending on some condition or value

The "if-else" statement https://en.wikipedia.org/wiki/Conditional_(computer_programming)#If.E2.80.93then .28.E2.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,
_

rahma_sassi
23rd December 2016, 23:07
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
12263

d_stranz
24th December 2016, 00:02
I think anda_skoa means something like this:



// 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.

anda_skoa
24th December 2016, 14:22
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,
_