9

I have an issue with a simple program. I'm opening a QFileDialog this way:

QFileDialog fileDialog(this);
fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
if (!fileDialog.exec())
return;

However it shows a Qt dialog instead the native Windows dialog. I'm using Windows 7 x64 and I really do preferr the native dialog instead of Qt dialog because it is a lil' bit more fancy. However I've read and I found that this can be changed by using:

fileDialog.setOption(QFileDialog::DontUseNativeDialog, false);

The fact is that I'm not getting the native Windows dialog but the Qt one, so that option is not working... Anyone knows how to solve this issue without using the static members?

I don't really want to use the static members because they have a kind of memory leak problem or something because if you open repeatedly new dialogs with the static member the memory used by your program increases and increases, however, using the dialog previously stored with a pointer doesn't have this problem.

So, if someone has an answer about this both things (Native dialog and memory leak problem) plz tell me.

Thanks.

daleotar
  • 315
  • 3
  • 6

2 Answers2

6

The native dialogs don't support the full array of features exposed by the QFileDialog class. That's why they are only available through the static short-cut functions called getOpenFileName(), getSaveFileName() etc'. If you're using these functions and still don't want to see the native dialog, you use the DontUseNativeDialog flag.

shoosh
  • 70,450
  • 50
  • 199
  • 310
  • thanks, I didn't know that native dialogs didn't support that... well... However, do you know a way to avoid that kind of "memory leaks"? ... I know that it is not technically a memory leak, however I want to know if there is a way to avoid that behavior of the static member... – daleotar Jun 19 '11 at 21:54
  • 1
    I never heard of that memory leak problem. Do you have more detailed information on this? If yes, report it as Qt bug. – Frank Osterfeld Jun 20 '11 at 05:57
  • 1
    I've never noticed any memory leak using these functions. – shoosh Jun 20 '11 at 10:53
  • yeah, as I said, it is not a memory leak technically but if you call the static member it creates a new child of the parent (mainwindow) but it never deletes because the parent(mainwindow) has the control of the child, so, the child is deleted when the parent is but not before... So, this causes that if you call the static member the memory used increases every time you call it... – daleotar Jun 21 '11 at 04:05
0

Are you sure that such a child is created? Because if so, I would have assumed that you could do something like

QString path = QFileDialog::getExistingDirectory(this, ...);

QFileDialog *filedialog = this->findChild<QFileDialog*>();
if (filedialog) {
    filedialog->deleteLater();
}

But I tried it creating the dialog with this as the parent and calling findChild in this object as well as creating the dialog using 0 as the parent and calling findChild in the main window; both to no avail.

steps
  • 588
  • 1
  • 5
  • 18