0

I'm writing a ui test for a Qt application. Now this application raises a QFileDialog which must be automatically filled in and committed.

I already have a QTimer which runs even when the modal dialog is shown. This approach works for many dialogs e.g. QMessageBox or QColorDialog.

The Problem is, that the QFileDialog is a native dialog. So I can't search for the dialog widget, because there is none.

Is there a way to access the native dialog.

I'm developing on Ubuntu so I guess it's a GTK dialog. The tests will always run on Ubuntu.

Thomas Klier
  • 449
  • 4
  • 16
  • 2
    I'd question the test here. You're clearly not wanting to test the functionality of the native dialog, but whether or not the resulting path is handled correctly. Wouldn't a stub function work better here, rather than calling the native dialog box? – TheDarkKnight Jun 11 '15 at 12:20
  • The dialog is raised in the middle of a function. Bypass the dialog would mean to rewrite this function. Maybe this is the best way. – Thomas Klier Jun 11 '15 at 12:28
  • 1
    Let's assume the file is a document for a text editor. If your function is directly calling the native file dialog, you're restricted to retrieving the file from the local machine or network. A requirement is introduced to support items in a database or even Cloud location. Your function should really call another, which can decide what mechanism to use to retrieve the data. This new function would then either call the native dialog, access a database, or cloud location. Your test of the original function is now viable. – TheDarkKnight Jun 11 '15 at 12:58
  • TheDarkNight: If it's a unit test, I agree, but if it's a UI test (like Squish does), it's a valid case to me – Frank Osterfeld Jun 11 '15 at 14:07

1 Answers1

0

Depending on your needs you could just set QFileDialog::DontUseNativeDialog to true using void QFileDialog::setOption(Option option, bool on = true) before you show the dialog. Then you should have a widget to search for.

See: http://doc.qt.io/qt-5/qfiledialog.html#setOption

acj
  • 73
  • 1
  • 9
  • As @acj says, you can instruct Qt not to use the native dialogs, so if that works for your case... Setting `QFileDialog::DontUseNativeDialog` is one way, creating the dialog yourself [as an instance of the `QFileDialog` class](http://doc.qt.io/qt-5/qfiledialog.html#QFileDialog) is another. (Only the static functions will use native dialogs.) You mentioned your existing method was working for `QColorDialog`, but you should watch out: `QColorDialog` and `QFontDialog` will also use native widgets on some platforms. Those classes have their own corresponding `::DontUseNativeDialogs` overrides. – FeRD Mar 17 '18 at 11:06
  • (Missed my edit window, but I meant both "native dialogs" (not "native widgets") and `::DontUseNativeDialog` (no plural), in that previous comment.) – FeRD Mar 18 '18 at 00:33