ok, i got a bit confused with my own code. Here's what i am doing now:
Header code:
{
---
---
---
public:
private:
};
Class TestPage : public QWidget
{
---
---
---
public:
static QComboBox *getTestCombo ();
private:
static QComboBox *sm_pTestCombo;
};
To copy to clipboard, switch view to plain text mode
CPP code
{
return sm_pTestCombo;
}
QComboBox* TestPage::sm_pTestCombo;
QComboBox * TestPage::getTestCombo ()
{
return sm_pTestCombo;
}
To copy to clipboard, switch view to plain text mode
Now, sm_pTestCombo is a private variable so it can't be accessed from the other class directly.
From the other class, i am calling getTestCombo() to get the combo box pointer.
QComboBox *testCombo
= TestPage
::getTestComboBox ();
QComboBox *testCombo = TestPage::getTestComboBox ();
To copy to clipboard, switch view to plain text mode
Does this approach look ok? The member variable is now private and other classes have to use the public member function to get the variable's address.
Bookmarks