PDA

View Full Version : Qfiledialog Problem - (Beginner)



kingslee
11th October 2006, 19:08
Hello guys,
I create simple designer application.
in which i implemeted a filedialog to retreive the file.

I followed the documentation, and did it .
It compiled & ran properly
and when i click the button , it just access the floppy drive and then nothing happens

<code>
void VRML2MVRDlg::on_Browse_clicked()
{
// QString filename = QFileDialog::getOpenFileName( QString::null, "VRML Files (*.wrl)", this, "file open", "VRML File Open" );
QFileDialog* fd = new QFileDialog(this);
fd->setDirectory("C:\\");
fd->setFileMode( QFileDialog::AnyFile);
fd->setViewMode(QFileDialog::Detail);
fd->setFilter("VRML Files (*.wrl)");
QStringList filenames = fd->selectedFiles();
QString filename;
if (!filenames.isEmpty())
filename = filenames[0];
}
<code>

Looking forward for your reply.

jpn
11th October 2006, 19:28
You have to call QDialog::exec() or QWidget::show() to make the file dialog visible. Most likely you want the first one which gives you a modal dialog (blocking until the user closes it).



if (filedialog->exec() == QDialog::Accepted)
{
// do something
}

kingslee
11th October 2006, 22:53
Thanks jpn for your reply.
Still I have a problem in displaying the file name in lineedit .
again ..
it compiles and nothing happens.

I inserted two lines to do it. I dont kow whether its right or?
m_VrmlFile is the object name of the lineedit.

code

QFileDialog* fd = new QFileDialog(this);
if(fd->exec()== QDialog::Accepted)
{
fd->setDirectory("C:\\");
fd->setFileMode( QFileDialog::ExistingFile);
// fd->setViewMode(QFileDialog::Detail);
fd->setFilter("VRML Files (*.wrl)");
QStringList filenames = fd->selectedFiles();
QString filename;
if (!filenames.isEmpty())
filename = filenames[0];

m_VrmlFile = new QLineEdit;
m_VrmlFile->setText(filename);
}

looking forward to your reply

kingslee
12th October 2006, 00:00
i got it ..
I should not use the first line, to create a new qlineedit object

thanks.