How to change ui something from different class
-
While certain function finish, I want to call different class's function , in which i update ui data, but nothing change. When i call this function from this class it works.
@beqa
Hi
Can you show some code?The normal way is to ask the other window to update a widget.
Or use signals and slots so "when certain function finish" it emit a signal
that you have connected to a slot in the other class. this slot then
updates. -
Hi
void Tunnelqtworking::on_actionResidual_triggered()
{
dif.Residual(); // solving ResidualForm res; // different class object res.update_data(); // update this data
}
void ResidualForm::update_data() // this update_data()
{
....ui.lcdNumber->display(r1); ui.lcdNumber->update();
}
-
Hi
void Tunnelqtworking::on_actionResidual_triggered()
{
dif.Residual(); // solving ResidualForm res; // different class object res.update_data(); // update this data
}
void ResidualForm::update_data() // this update_data()
{
....ui.lcdNumber->display(r1); ui.lcdNumber->update();
}
@beqa
Well, ResidualForm res; is a local variable and it will deleted as soon as
on_actionResidual_triggered ends so it only be shown on screen for a very short time.Try to new it
ResidualForm *res= new ResidualForm(this); // use this to give it a parent, else you leak
res->update_data(); // update this data
res->show();Also is ResidualForm ment to be a Dialog and popup or how was it planned to be shown ?
You are not inserting it into anything. -
I have tried signal and slot, but has not worked.
I emit like thisvoid Tunnelqtworking::on_actionResidual_triggered()
{
dif.Residual(); // solvingResidualForm res; // different class object
emit update_data(5); // I figured out ,that it needs a parameter
}
but in ResidualForm i can't create Tunnelqtworking object, its big and give me unclear errors -
I have tried signal and slot, but has not worked.
I emit like thisvoid Tunnelqtworking::on_actionResidual_triggered()
{
dif.Residual(); // solvingResidualForm res; // different class object
emit update_data(5); // I figured out ,that it needs a parameter
}
but in ResidualForm i can't create Tunnelqtworking object, its big and give me unclear errors -
i try on debug and it enter ordinary this update_data function, but dont change ui element. Seems, ui has restriction from outside
@beqa
well in this case, you should NOT make a new one. you should
use the one you insert.ui.tabWidget->addTab(new ResidualForm(), "Residual");
--->
ResidualForm *res; // THIS IN H
and u add it
res=new ResidualForm()
ui.tabWidget->addTab(res, "Residual");so its the same.
res->update_data() is for the same shown on screen.Do NOT create new one as its not related to the one shown on screen.
So the error is. You insert one , you see on screen.
Then you create a SECOND one that you update but its never shown on screen. -
THANK YOU, YOU ARE WELCOME. ITS WORK.
Differently, I wonder is it possible to change different class's ui?@beqa said in How to change ui something from different class:
, I wonder is it possible to change different class's ui?
They are private for the reason, that one should not directly access another's Windows
widgets.
But you can move it to public and you can access ui-> from outside but this leads
to bad code and not a good idea.
Its much better to provide function the outside can use
Like your update_dataIf you allow the outside to know the inner details of other classes, you get spaghetti code and
a little change will result in many other changes in rest of program.