Function acces in mainwindow class from a dialog class?
Hi all,
I have the following classes:
MainWindow class:
Code:
namespace Ui {
class MainWindow;
}
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
};
ui->setupUi(this);
}
return "...";
}
Dialog class:
Code:
namespace Ui {
class Dialog;
}
Q_OBJECT
void anyFunction();
public:
explicit Dialog
(QWidget *parent
= 0);
};
Dialog
::Dialog(QWidget *parent
) : QDialog(parent
), ui
(new Ui
::Dialog) { ui->setupUi(this);
}
void Dialog::anyFunction() {
qDebug() << MainWindow->someData();
}
In the Dialog class (row 19.): how can I access the someData() function from MainWindow?
Thanks in advance!
Chris
Re: Function acces in mainwindow class from a dialog class?
You need a pointer to MainWindow instance.
Re: Function acces in mainwindow class from a dialog class?
That is obvious to me, but how I surrender the pointer?
Re: Function acces in mainwindow class from a dialog class?
I assume you are calling the dialog from within the main window, so you can call some custom method that will feed this pointer to the dialog. However if the goal of your MainWindow::someData() is to provide data for the dialog, it is better to add a method to the dialog that allows to pass (and store) the data object directly from the window when the dialog gets called.
Re: Function acces in mainwindow class from a dialog class?
Ok, thanks for your help!