From the code, we can conclude that the DashBoard class inherits QObject . The parent a QObject field is defined as a pointer to a QObject , so when you call parent->ui->menuSL->setCurrentIndex(0); inside the method of the DashBoard class, you assume that QObject defines a member named ui > which is incorrect.
Just highlight the parent this way:
((MainWindow*)(parent()))->ui->menuSL->setCurrentIndex(0);
or this one:
MainWindow* parent = qobject_cast<MainWindow*>(this->parent()); // check parent is not null parent->ui->menuSL->setCurrentIndex(0);
You do not see an error in the constructor, because parent is defined as a pointer to an object of the MainWindow class, and then passed to the QObject constructor.
Remember to make ui public and include the header of the automatically generated user interface if you use Qt Designer (in your case, probably "ui_mainwindow.h" ) in the DashBoard cpp file.
NOTE. I'm just trying to answer your question, but I recommend that you look at how you do it. There are several ways to achieve this with a more consistent OO design.
mhcuervo
source share