PDA

View Full Version : problem using gui objects after leving the main class



ruben.rodrigues
17th June 2010, 09:39
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:


void EFrwClient::gui_settings(QString level)
{
if (level == "starting")
{
//Gui Settings
ui.setupUi(this);
cout << "--Default Settings--" << endl;
ui.frame_2->setVisible(false);
ui.pushButton_6->setVisible(false);
}

if (level == "power_user")
{
cout << "--Gui Settings--" << endl;
ui.pushButton_6->setVisible(true);
}
}

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":


EFrwClient *gui_class = new EFrwClient;
gui_class->load_modules(name,loginlevel);

the function is suppose to do:

cout << "--Gui Settings--" << endl;
ui.pushButton_6->setVisible(true);

but only the cout is executed...

What could be the problem?

Thanks in advance.

tbscope
17th June 2010, 09:57
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.

ruben.rodrigues
17th June 2010, 10:27
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".


EFrwClient::EFrwClient(QWidget *parent)
: QWidget(parent)
{

gui_settings("starting","no_name");

//Connect pushButtons
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(request_load()));

}

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


void EFrwClient::gui_settings(QString level, QString name)
{
if (level == "starting")
{
//Gui Settings
ui.setupUi(this);
cout << "--Default Settings--" << endl;
ui.frame_2->setVisible(false);
ui.pushButton_6->setVisible(false);
}

if (level == "power_user")
{
ui.setupUi(this);
cout << "--Gui Settings--" << endl;
ui.pushButton_6->setVisible(true);
}
}

2- The user writes the user name and the password, clicks the login button which will call a function in the class EUserCtrl_Client:


EUserCtrl_Client *_userctrl = new EUserCtrl_Client();
_userctrl->Load(ui.lineEdit->text(), ui.lineEdit_2->text(), EnumUser::eUserLevel_None);


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.


EFrwClient *gui_class = new EFrwClient;
ui_class->load_modules(name,loginlevel);


void EFrwClient::gui_settings(QString level, QString name)
{
if (level == "starting")
{
//Gui Settings
ui.setupUi(this);
cout << "--Default Settings--" << endl;
ui.frame_2->setVisible(false);
ui.pushButton_6->setVisible(false);
}

if (level == "power_user")
{
ui.setupUi(this);
cout << "--Gui Settings--" << endl;
ui.pushButton_6->setVisible(true);
}
}

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

wysota
17th June 2010, 11:33
Are you starting the application event loop? Aren't you blocking it with some for() or while() loop?

ruben.rodrigues
17th June 2010, 11:48
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!

wysota
17th June 2010, 13:50
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?

ruben.rodrigues
17th June 2010, 14:08
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!

wysota
17th June 2010, 18:43
But what exactly doesn't work? :confused: