Results 1 to 8 of 8

Thread: problem using gui objects after leving the main class

  1. #1
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default problem using gui objects after leving the main class

    Hi!

    I am not a experienced qt user and this question may have a basic solution or could be something that I am missing.

    I have QT Gui Project and the ui's name is EFrw_client. The class EFrw_client has a function that looks like this:

    Qt Code:
    1. void EFrwClient::gui_settings(QString level)
    2. {
    3. if (level == "starting")
    4. {
    5. //Gui Settings
    6. ui.setupUi(this);
    7. cout << "--Default Settings--" << endl;
    8. ui.frame_2->setVisible(false);
    9. ui.pushButton_6->setVisible(false);
    10. }
    11.  
    12. if (level == "power_user")
    13. {
    14. cout << "--Gui Settings--" << endl;
    15. ui.pushButton_6->setVisible(true);
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    The idea is to get a qstring with the user level and according to it, it will activate buttons. The functions is first called at the constructor with the parameter "starting".

    When the user presses the login button another class, called EUserCtrl, is activated and this class is responsible to send the login name and password to a data server that check if the parameters match with a set in the database. Then, that server return the user information, which includes the login level. The class EUserCtrl gets the login level and calls the function gui_settings with the parameter "power_user":

    Qt Code:
    1. EFrwClient *gui_class = new EFrwClient;
    2. gui_class->load_modules(name,loginlevel);
    To copy to clipboard, switch view to plain text mode 

    the function is suppose to do:
    Qt Code:
    1. cout << "--Gui Settings--" << endl;
    2. ui.pushButton_6->setVisible(true);
    To copy to clipboard, switch view to plain text mode 

    but only the cout is executed...

    What could be the problem?

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: problem using gui objects after leving the main class

    Can you post the complete source code. It's not easy to follow right now.

    A good solution is to work with signals and slots. Create a custom signal to set the user level and in your window or widget create a slot that listens to this signal.
    You can also work with events.
    Or return values.

  3. #3
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem using gui objects after leving the main class

    Quote Originally Posted by tbscope View Post
    Can you post the complete source code. It's not easy to follow right now.

    A good solution is to work with signals and slots. Create a custom signal to set the user level and in your window or widget create a slot that listens to this signal.
    You can also work with events.
    Or return values.
    I would like to post my code but unfortunally not all of it is mine and my boss/co-workers would not be happy to see it on-line.

    I will try to explain step by step what I do:

    1- Start the contructor and set the gui settings. My gui has a lot of frames and buttons but only 1 button and 1 frame are visible. That is when you call function gui_settings with the parameter "starting".
    Qt Code:
    1. EFrwClient::EFrwClient(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4.  
    5. gui_settings("starting","no_name");
    6.  
    7. //Connect pushButtons
    8. connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(request_load()));
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    this proves that the function works as the buttons and frames disapeer:

    Qt Code:
    1. void EFrwClient::gui_settings(QString level, QString name)
    2. {
    3. if (level == "starting")
    4. {
    5. //Gui Settings
    6. ui.setupUi(this);
    7. cout << "--Default Settings--" << endl;
    8. ui.frame_2->setVisible(false);
    9. ui.pushButton_6->setVisible(false);
    10. }
    11.  
    12. if (level == "power_user")
    13. {
    14. ui.setupUi(this);
    15. cout << "--Gui Settings--" << endl;
    16. ui.pushButton_6->setVisible(true);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    2- The user writes the user name and the password, clicks the login button which will call a function in the class EUserCtrl_Client:
    Qt Code:
    1. EUserCtrl_Client *_userctrl = new EUserCtrl_Client();
    2. _userctrl->Load(ui.lineEdit->text(), ui.lineEdit_2->text(), EnumUser::eUserLevel_None);
    To copy to clipboard, switch view to plain text mode 

    that class EUserCtrl_Client is responsible for all the tcp connections. It sends the user name, which is the ui.lineEdit->text(), the password, ui.lineEdit_2->text(), and a empty user enumeration. The database server checks the user and password and sends back the UserLevel.

    3- When the class EUserCtrl_Client gets the answer from the server, calls the gui_settings function (from the class EFrwClient) with the user level according the user entered before.

    Qt Code:
    1. EFrwClient *gui_class = new EFrwClient;
    2. ui_class->load_modules(name,loginlevel);
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. void EFrwClient::gui_settings(QString level, QString name)
    2. {
    3. if (level == "starting")
    4. {
    5. //Gui Settings
    6. ui.setupUi(this);
    7. cout << "--Default Settings--" << endl;
    8. ui.frame_2->setVisible(false);
    9. ui.pushButton_6->setVisible(false);
    10. }
    11.  
    12. if (level == "power_user")
    13. {
    14. ui.setupUi(this);
    15. cout << "--Gui Settings--" << endl;
    16. ui.pushButton_6->setVisible(true);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    I am sure that the line ui.pushButton_6->setVisible(true); is execute but with no efect.


    I hope that you can understand this better now.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem using gui objects after leving the main class

    Are you starting the application event loop? Aren't you blocking it with some for() or while() loop?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem using gui objects after leving the main class

    Quote Originally Posted by wysota View Post
    Are you starting the application event loop? Aren't you blocking it with some for() or while() loop?
    Thanks for your tip.

    No, I don't have any loop blocking the setvisible. I even closed the tcp just for checking.

    If someone comes with an idea please share it. Meanwhile I will work with 2 windows.

    Thanks to all!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem using gui objects after leving the main class

    Quote Originally Posted by ruben.rodrigues View Post
    Meanwhile I will work with 2 windows.
    Hmm... what exactly is the problem? I don't see how using one or two windows makes any difference for anything. Could you prepare a minimal compilable example reproducing the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2010
    Posts
    100
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: problem using gui objects after leving the main class

    Quote Originally Posted by wysota View Post
    Hmm... what exactly is the problem? I don't see how using one or two windows makes any difference for anything. Could you prepare a minimal compilable example reproducing the problem?
    I also don't understand why it doesn't work in that function and it works in other functions. Basically I can use the setvisible until I call the 2nd class and then if I do it nothing happens.

    Now I can't recreate and example but I will make something later and then I nudge you.

    thanks!

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem using gui objects after leving the main class

    But what exactly doesn't work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Instantiate objects only having their class name
    By victor.fernandez in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2009, 16:22
  2. Replies: 1
    Last Post: 25th July 2008, 23:44
  3. using class objects globally??????
    By pratik in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2007, 13:51
  4. Replies: 4
    Last Post: 26th June 2007, 19:19
  5. Replies: 7
    Last Post: 18th July 2006, 21:33

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
  •  
Qt is a trademark of The Qt Company.