NPorwal
NPorwal

Reputation: 21

back and forward button in QFileDialog dont have signals

I'm using QFileDialog::DontUseNativeDialog. Now I'm having trouble with the signals. Here is my sample Code:

class A : public QFileDialog
{
    A(){
       setOption(QFileDialog::DontUseNativeDialog);
       connect(this, SIGNAL(directoryEntered(const Qstring), this, SLOT(foo(const QString)));
    }

    foo(const QString path){
    QDir dir(path);
    // Code...
   }
};

Now when I use the DontUseNativeDialog option, I get three navigation buttons at upper right side of the dialog, which are:

 1. Back
 2. Forward
 3. Parent Directory

When I press the Parent Directory button then the signal directoryEntered(const QString) gets fired. But it does not work in case of Back and Forward button. Is there any different signal which I can use. Please help. Thank you.

Upvotes: 2

Views: 628

Answers (1)

Michael Starke
Michael Starke

Reputation: 316

Had the same problem with QFileDialog and Qt4.8.x

Solution was to manually emit the signals on button clicks:

class FileDialog : public QFileDialog {

public:    
    FileDialog() : QFileDialog() {
        this->fixHistoryButtons();
    }

private:
    void fixHistoryButtons() {
        QToolButton backButton = this->findChild<QToolButton *>("backButton");
        QToolButton forwardButton = this->findChild<QToolButton *>("forwardButton");
        this->connect(backButton, SIGNAL(clicked()), SLOT(backOrForwardButtonClicked()));
        this->connect(forwardButton, SIGNAL(clicked()), SLOT(backOrForwardButtonClicked()));
    }
private slots:
    void backOrForwardButtonClicked() {
        /* this->directory() should be save, since we should be called after QFileDialog has done it's thing */
        emit this->directoryChanged( this->directory().absolutePath() );
    }
};

Upvotes: 4

Related Questions