Results 1 to 5 of 5

Thread: open a window according to the type chosen in mainwindow

  1. #1
    Join Date
    Dec 2016
    Posts
    3
    Qt products
    Qt5 Qt Jambi
    Platforms
    Windows

    Default 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
    la2.PNG
    After another window will be opened to connect or register
    mainwindow.PNG
    If it clicks on join I want another window will be opened but depending on the type of user.
    mainwindow.cpp
    join_connect.cpp


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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    Dec 2016
    Posts
    3
    Qt products
    Qt5 Qt Jambi
    Platforms
    Windows

    Default 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:n_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:n_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
    mainwindow.h

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: open a window according to the type chosen in mainwindow

    I think anda_skoa means something like this:

    Qt Code:
    1. // pseudocode
    2. void MainWindow::on_pushButton_3_clicked()
    3. {
    4. switch ( userType )
    5. {
    6. case User:
    7. showUserWindow();
    8. break;
    9.  
    10. case Doctor:
    11. showDoctorWindow();
    12. break;
    13.  
    14. case Administrator:
    15. showAdminWindow();
    16. break;
    17.  
    18. default:
    19. // error - no such user type
    20. break;
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by d_stranz; 24th December 2016 at 00:07.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: open a window according to the type chosen in mainwindow

    Quote Originally Posted by rahma_sassi View Post
    C:\Users\LENOVO\Desktop\projet c++\code-sql\smart health v1\smart_health\mainwindow.h:26: error: 'void MainWindow:n_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:n_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,
    _

Similar Threads

  1. Replies: 2
    Last Post: 14th January 2013, 08:07
  2. Replies: 0
    Last Post: 9th May 2010, 21:49
  3. Open Dialog from MainWindow.
    By halvors in forum Qt Programming
    Replies: 8
    Last Post: 1st April 2010, 02:09
  4. Open mainwindow
    By cwnelatury in forum Newbie
    Replies: 1
    Last Post: 17th April 2009, 23:46
  5. couldn't open fontconfigs chosen font with Xft!!!
    By Kenneth Freidank in forum Qt Programming
    Replies: 0
    Last Post: 5th October 2006, 04:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.