1

I have a QFileDialog in Qt for saving a file.

It is not smmiting signals. I connect it via QFileDialog diag(this); ...

connect(
        dialog, SIGNAL(filterSelected(const QString&)),
        this,                 SLOT(saveAsDiagFilterSelected(const QString&)),
        Qt::QueuedConnection);

Then call it with exec(). The saveAsDiagFilterSelected is never called.

What might be wrong?


This is how I create my dialog:

dialog = new QFileDialog(this);
dialog->setFileMode(QFileDialog::AnyFile);
dialog->setNameFilters(filterList);
dialog->setAcceptMode(QFileDialog::AcceptSave);
dialog->setWindowTitle(windowTitle);

I tried implementing the new signal API (as suggested in comments):

connect(
        dialog, &QFileDialog::filterSelected,
        this,   &MainWindow::saveAsDiagFilterSelected);

but still no results.


Update

Found out that using the OS native dialog (I'm under Linux, dont know if this happens in other SO's), is creating the problem. If I do

dialog->setOption(QFileDialog::DontUseNativeDialog, true);

the signal is emmited. How can I workaround this?

manatttta
  • 3,054
  • 4
  • 34
  • 72
  • Remove `const` and the reference from your signal/slot signatures. – jonspaceharper May 30 '16 at 15:44
  • Works for me. Do you see "no such slot ..." in stderr? BTW: If you do `QFileDialog diag(this)`, then your connect should start with `connect(&diag, ...` – Karsten Koop May 30 '16 at 16:08
  • 1
    Consider using the [new signal slot syntax](https://wiki.qt.io/New_Signal_Slot_Syntax). This produces compile-time errors instead of runtime-errors as with the old syntax (using `SIGNAL` and `SLOT` macros). – IInspectable May 30 '16 at 16:12
  • @KarstenKoop I get no runtime errors – manatttta May 30 '16 at 17:12
  • @IInspectable I get no runtime errors! Changing to the new signal API did not solve the problem :( – manatttta May 30 '16 at 17:12
  • Failure to bind to a class member using the old (pre Qt5) syntax writes messages to the debug stream. This is written to *stderr* on *nix systems, and to the debug output (see [OutputDebugString](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363362.aspx)) on Windows. Did you verify that you didn't get any messages on those output streams? – IInspectable May 30 '16 at 17:38
  • @IInspectable i am using Linux, I can see the stderr output, and I have no errors. I have seen them before in other cases. Furthermore, I implemented the new connect API and get no compile errors – manatttta May 30 '16 at 17:43
  • Have you tried using the new signal/slot syntax? https://wiki.qt.io/New_Signal_Slot_Syntax ... It finds more problems at compile time. –  May 30 '16 at 17:43
  • @Bugfinger yes I did. no results – manatttta May 30 '16 at 17:43
  • @manatttta, I think the answer for your question in **update** zone [here](http://stackoverflow.com/a/6405275/6318750). – Shtol Krakov May 30 '16 at 18:57

2 Answers2

2

The native dialog on your platform does not inform the user about filter changes, so there's nothing for Qt to emit signals on - it isn't possible with that particular native dialog. Or perhaps the requisite functionality isn't implemented in Qt. This behavior is platform specific. It works on Windows at least.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • @manatttta Why do you assume that your platform supports this? What **is** your platform? – Kuba hasn't forgotten Monica May 30 '16 at 20:23
  • I am using Linux. This will be a cross plaform tool (UNIX + Windows). I am not assuming it, I discarded using that signal, so I am looking for a workaround to be informed when the user changes the filter, so that can force the default suffix on the "Save As" dialog – manatttta May 30 '16 at 20:32
  • Sorry for not being clear on the meaning of platform. What *exact* UI style is Qt using on your system? The obvious workaround is to **use** the signal and use non-native style on Unices other than OS X. – Kuba hasn't forgotten Monica May 30 '16 at 20:36
  • But I shall use the native dialog. I am not sure about the UI style, I am under Ubuntu Linux (one of the platforms that shall be supported) – manatttta May 30 '16 at 20:38
  • There isn't really a "native" dialog to Ubuntu. You can be running gnome or kde, and Qt might integrate with gnome's dialogs to some extent. Most likely that integration doesn't implement filter switching signals. You have to look in Qt source code to see what's supported, and whether you could patch your copy of Qt to fix that. – Kuba hasn't forgotten Monica May 30 '16 at 23:07
1

Try setting slots/signals like this:

connect(
        dialog, SIGNAL(filterSelected(QString)),
        this, SLOT(saveAsDiagFilterSelected(QString)),
        Qt::QueuedConnection);
ahmed
  • 5,430
  • 1
  • 20
  • 36