This is a question that I can't seem to figure out for some reason I don't know why but...
I have a main class which includes the header files of all the other classes and in the cpp of the main class it goes something like this...
MainClass
::MainClass(QWidget *parent
) : QWidget(parent
), mainWindow
(new Ui
::MainClass){
mainWindow->setupUi(this);
classTwo = new SecondClass(this);
classThree = new ThirdClass(this);
}
MainClass::MainClass(QWidget *parent) : QWidget(parent), mainWindow(new Ui::MainClass)
{
mainWindow->setupUi(this);
classTwo = new SecondClass(this);
classThree = new ThirdClass(this);
}
To copy to clipboard, switch view to plain text mode
but in classTwo for instance I want to disable a button in classThree. Now I can do this through the mainClass say like this...
connect(classTwo->classTwoGui->disableClassThree_Button, SIGNAL(clicked()), this, SLOT(disableButtonInClassThree()));
connect(classTwo->classTwoGui->disableClassThree_Button, SIGNAL(clicked()), this, SLOT(disableButtonInClassThree()));
To copy to clipboard, switch view to plain text mode
where in the above example disableButtonInClassThree() would be a member function of the main class and the function defined in the MainClass cpp would probably be...
void MainClass::disableButtonInClassThree()
{
classThree->classThreeGui->buttonOne->setEnabled(false);
}
void MainClass::disableButtonInClassThree()
{
classThree->classThreeGui->buttonOne->setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
the problem is that I don't want to go through MainClass as I'd imagine that is very inefficient and creates a cluttered clumsy MainClass when using way more than 2 other classes in interaction so I talked to a couple friends and they told me to try this...
In the SecondClass header I have...
#include "thirdclass.h"
{
Q_OBJECT
public:
SecondClass
(ThirdClass
*test,
QWidget *parent
= 0);
Ui::SecondClass *classTwoGui;
public slots:
void on_disableClassThree_Button_clicked();
}
#include "thirdclass.h"
class SecondClass : public QMainWindow
{
Q_OBJECT
public:
SecondClass (ThirdClass *test, QWidget *parent = 0);
Ui::SecondClass *classTwoGui;
public slots:
void on_disableClassThree_Button_clicked();
}
To copy to clipboard, switch view to plain text mode
In the SecondClass cpp I have...
SecondClass
::SecondClass (ThirdClass
*test,
QWidget *parent
) : QMainWindow(parent
), classTwoGui
(new Ui
::SecondClass ){
classTwoGui->setupUi(this);
test->classThreeGui->buttonOne->setEnabled(false);
}
SecondClass::SecondClass (ThirdClass *test, QWidget *parent) : QMainWindow(parent), classTwoGui(new Ui::SecondClass )
{
classTwoGui->setupUi(this);
test->classThreeGui->buttonOne->setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
Now the above code works BUT it only works in the constructor of SecondClass so essentially meaning I can't really control it through a button clicked in SecondClass because doing any code outside of the constructor is not recognizing test.
I have thus researched all over and found nothing to help, I have tried forward class declarations but that's not my problem I believe and that didn't work either, I have also tried taking it out of the constructor and initializing a pointer of the ThirdClass below the constructor such as...
public:
ThirdClass *test,
Ui::SecondClass *classTwoGui;
public:
SecondClass (QWidget *parent = 0);
ThirdClass *test,
Ui::SecondClass *classTwoGui;
To copy to clipboard, switch view to plain text mode
which could then be accessed in any function inside of the SecondClass but then it caused an instant crash upon launching I believe due to the fact that in the MainClass it is also being initialized too??
I almost forgot to mention that in order for me to get the constructor working working I had to change...classTwo = new SecondClass(this); in the MainClass constructor to...
classTwo = new SecondClass(classThree, this);
classTwo = new SecondClass(classThree, this);
To copy to clipboard, switch view to plain text mode
I hope someone can help me as I'm really struggling with this part and I have had no success for awhile although I can still get it to work the inefficient way by going through the MainClass but I'd rather not due to the reasons above so simply put...
I need to access GUI objects, such as a button, from a class using another class without going through the MainClass.
Final Example to hopefully clear things up is...
Clicking a button in a second class GUI will disable a button in a third class GUI without going through the main class, essentially have the second class somehow recognize GUI objects of the third class in any section of the second class so any member function of the second class can interact with objects of the third class.
I hope this all makes sense I tried my best to explain it, sorry if it's to long 
Thanks again for trying to help!!!
Bookmarks