Invoking a QFileDialog from another dialog
Hi,
I want to invoke a FileDialog from another dialog window :
I am in my tool options configuration dialog box (which works in a classic manner, with Accept/Cancel buttons which respectively accept new configuration or cancel changes). In one of this, I need to make user select a directory, so I want to invoke QFileDialog for this.
But system hangs at runtime, due to modal aspects.
Any idea to launch QFileDialog from a dialog ?
BR
Re: Invoking a QFileDialog from another dialog
Hi there!
I was curious if I could reproduce this problem:
Code:
project file:
TEMPLATE = app
TARGET = modalmodal
SOURCES += main.cpp
HEADERS += forms.h
forms.h
#ifndef FORMS_H
#define FORMS_H
#include <QtGui>
#include <QDebug>
class OptionDialog
: public QDialog{ Q_OBJECT
public:
OptionDialog() {
setModal(true);
setGeometry(100,100,320,240);
setAttribute(Qt::WA_DeleteOnClose,true);
connect(button,SIGNAL(clicked()),this,SLOT(openFileDialog()));
}
protected slots:
void openFileDialog() {
QString fileName
= QFileDialog::getOpenFileName(this,
"Test Dialog",
"",
"Zip-File (*.zip)");
qDebug() << fileName;
}
private:
};
{ Q_OBJECT
public:
MainForm() {
setGeometry(50,50,640,480);
connect(button,SIGNAL(clicked()),this,SLOT(showOptionDlg()));
}
protected slots:
void showOptionDlg() {
OptionDialog* opt = new OptionDialog();
opt->show();
}
private:
};
#endif // FORMS_H
main.cpp:
#include <QtGui>
#include <QApplication>
#include "forms.h"
int main(int argc, char *argv[])
{
MainForm mainform;
mainform.show();
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
return app.exec();
}
This works without any problems..
Did you maybe miss to pass the modal option dialog as parent to the FileDialog?
Johannes
Re: Invoking a QFileDialog from another dialog
OK, thanks to your example, I understood the error : It was related to modal as you suggested.
Many thanks.