Answer the question
In order to leave comments, you need to log in
How to give a command to a button?
How to give QDialogButtonBox::Ok a command? At least for closing
file.h
#ifndef FILE_H
#define FILE_H
#include <QDialog>
namespace Ui {
class File;
}
class File : public QDialog
{
Q_OBJECT
public:
explicit File(QWidget *parent = nullptr);
~File();
private:
Ui::File *ui;
void okCliced();
signals:
void filePath(const QString &str); // генерация сигнлала filePath
};
#endif // FILE_H
#include "file.h"
#include "ui_file.h"
#include <QPushButton>
File::File(QWidget *parent) :
QDialog(parent),
ui(new Ui::File)
{
ui->setupUi(this);
connect(ui->buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()), SLOT(okCliced())); // ТУТ
connect(ui->buttonBox->button(QDialogButtonBox::Cancel),SIGNAL(clicked()), SLOT(close()));
}
void File::okCliced()
{
//emit filePath(ui->lineEdit->text()); /// генерировать сигнал
close();
}
File::~File()
{
delete ui;
}
Answer the question
In order to leave comments, you need to log in
Well, for starters, there is doc.qt.io/qt-5/qfiledialog.html for your purposes with a bunch of static methods for all occasions. And use it.
If you added all the buttons to the buttonBox, then your code should work. To close a dialog, call the doc.qt.io/qt-5/qdialog.html#done method .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question