Hi. I am a beginner and i have been facing this problem since Monday. I made a QMainWindow with name window and added an action in it. So when a user clicks the action, the QDialog dialog is displayed. In dialog i take input from user and then return it to window for display. I have set QMainWindow window as parent to QDialog dialog. Now How can i call the function of QMainWindow when OK button is clicked. Here is the code.
Please Please Explain me how to call QMainWindow functions from its child dialog in SIMPLE coding. I will really be thankful to you people.
this is .cpp file of QDialog
#include "itemdialog.h"
#include "ui_itemdialog.h"
#include "mainwindow.h"
ItemDialog::ItemDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ItemDialog)
{
ui->setupUi(this);
setWindowTitle("Status Dialog");
}
ItemDialog::~ItemDialog()
{
delete ui;
}
void ItemDialog::on_pushButton_clicked()
{
MainWindow obj;
obj.okbuttonclicked(ui->lineEdit->text());
}
Header file of QDialog
#ifndef ITEMDIALOG_H
#define ITEMDIALOG_H
#include <QDialog>
class MainWindow;
namespace Ui {
class ItemDialog;
}
class ItemDialog : public QDialog
{
Q_OBJECT
public:
explicit ItemDialog(QWidget *parent = 0);
~ItemDialog();
private slots:
void on_pushButton_clicked(); // when OK button is clicked this function is called automatically
private:
Ui::ItemDialog *ui;
};
#endif // ITEMDIALOG_H