As a beginner in Qt with C++, I am having difficulty in accessing members of my MainWindow object from a Dialog object.
My dialog object is from a class called Month, and below is my code:
I have a comboBox in MainWindow where I want the user to select a month, and then store the string for that month in a private variable called monthSelected as follows:
void MainWindow::on_monthComboBox_activated(const QString &arg1) { monthSelected = arg1; qDebug()<<"Month Selected is " << monthSelected << endl; }
I get the correct output after selecting the month, but when I try to retrieve the value of monthSelected in my Month dialog class via a getter function, then I get an empty string as output.
Month::Month(QWidget *parent) : QDialog(parent), ui(new Ui::Month) { ui->setupUi(this); MainWindow *mainWindow = new MainWindow(); qDebug()<<mainWindow->getMonthSelected(); }
As you can see, I created a pointer to MainWindow in order to access the getter function in my Month class, and I suspect this is where my error lies.
Is this the correct way to access members from the MainWindow class in a dialog, and if not, how would I go about doing it correctly?