Access form's widget's in other class
Hello,
i have a form manager.ui whose cpp file manager.cpp is as follows,
Code:
#include "manager.h"
#include "ui_manager.h"
manager
::manager(QWidget *parent
) : ui(new Ui::manager)
{
ui->setupUi(this);
}
manager::~manager()
{
delete ui;
}
void manager
::changeEvent(QEvent *e
) {
switch (e->type()) {
ui->retranslateUi(this);
break;
default:
break;
}
}
void manager::on_PB_General_clicked()
{
GetSystem_General();
}
This GetSystem_General() is in file applysettings.cpp file as folows,
Code:
#include "applysettings.h"
#include "ui_manager.h"
#include "../extras/Connections.h"
void GetSystem_General()
{
//Here i want to access the manager class's widget QLabel for e.g LB_Cpu and set its text using setText method like,
ui->LB_Cpu->setText("intel");
}
so my question is how to access the manager class widgets in this applysettings.cpp.
Re: Access form's widget's in other class
Quote:
Originally Posted by
p3c0
so my question is how to access the manager class widgets in this applysettings.cpp.
Normaly you shouldn't do that. better use getter and setter methods or return a value from GetSystem_General() and set it to your line edit inside your class manager. But if you really whant to change your gui in that other function, just pass a pointer to your manager class to GetSystem_General().
Re: Access form's widget's in other class
Thanks for reply Lykurg,
but the applysettings.cpp which contains GetSystem_General() is fully implemented. Restricted to use the getter setter methods.
what pointer i have to pass to GetSystem_General() ?
can you give an example
Re: Access form's widget's in other class
I strongly recommend that you follow one of the first two recommendation that Lykurg gave you.
The first is way to go, so use getter and setter functions for manager class (to access/set/modify the ui components)
The pointer passing "stuff" won't be able to access the ui pointer (because is default private) and i don't recommend to make it public for this reason (when is another way to solve the problem, keep that pointer private ;) )