
Originally Posted by
tbscope
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
){
gui_settings("starting","no_name");
//Connect pushButtons
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(request_load()));
}
EFrwClient::EFrwClient(QWidget *parent)
: QWidget(parent)
{
gui_settings("starting","no_name");
//Connect pushButtons
connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(request_load()));
}
To copy to clipboard, switch view to plain text mode
this proves that the function works as the buttons and frames disapeer:
{
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);
}
}
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);
}
}
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:
EUserCtrl_Client *_userctrl = new EUserCtrl_Client();
_userctrl->Load(ui.lineEdit->text(), ui.lineEdit_2->text(), EnumUser::eUserLevel_None);
EUserCtrl_Client *_userctrl = new EUserCtrl_Client();
_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.
EFrwClient *gui_class = new EFrwClient;
ui_class->load_modules(name,loginlevel);
EFrwClient *gui_class = new EFrwClient;
ui_class->load_modules(name,loginlevel);
To copy to clipboard, switch view to plain text mode
{
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);
}
}
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);
}
}
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
Bookmarks