4
Good morning dear,
created a project (Qt Widget Application) with Qt Creator (Qt 5.6.1).
The project has the following structure:
myproject.pro
Headers
dialogform. h
mainwindow. h
Sources
dialogform.cpp
main.cpp
mainwindow.cpp
Forms
dialogform. h
mainwindow. h
When I click on the pushbutton Dialogform, need to call the function clear() of Mainwindow
I have heard that I will need to do this through Signals and slots. I have read the documentation about, but I have not yet been able to make the connection.
Could someone give me a hand on this connect?
Thank you very much
dialogform. h
#ifndef DIALOGFORM_H
#define DIALOGFORM_H
#include <QDialog>
namespace Ui {
class DialogForm;
}
class DialogForm : public QDialog
{
Q_OBJECT
public:
explicit DialogForm(QWidget *parent = 0);
~DialogForm();
private slots:
private:
Ui::DialogForm *ui;
};
#endif // DIALOGFORM_H
mainwindow. h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void clear();
private slots:
void on_pbCallDialog_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
dialogform.cpp
#include "dialogform.h"
#include "ui_dialogform.h"
#include "mainwindow.h"
DialogForm::DialogForm(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogForm)
{
ui->setupUi(this);
connect(); // ajuda aqui.
}
DialogForm::~DialogForm()
{
delete ui;
}
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dialogform.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pbCallDialog_clicked()
{
DialogForm *dialogForm = new DialogForm(this);
dialogForm->show();
}
void MainWindow::clear()
{
ui->lineEdit->clear();
}
It worked, Thank you very much Luiz!!! a big hug!
– Juliano Gomes
I’m glad it worked out. If the answer helped you, please consider marking it as accepted.
– Luiz Vieira