Question

Why setWindowFilePath didn't work? Slot is working. The window title does not change. My OS is Windows 7, Qt was compiled with wchar_t support.

test::test(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
  ui.setupUi(this);
  QObject::connect(ui.pushButton, SIGNAL(clicked()), SLOT(Click()));
  setWindowTitle("Title");
}

void test::Click()
{
  setWindowFilePath("file.txt");
}
Was it helpful?

Solution

Maybe your problem is that you already used setWindowTitle() before using setWindowFilePath(). From the docs:

If the window title is set at any point, then the window title takes precedence and will be shown instead of the file path string.

Edit: I just tried using setWindowFilePath() and noticed that it only takes effect if you call it after you call show(). Since this isn't mentioned in the docs, it smells like a bug...

Edit: Well, if it doesn't work without using setWindowTitle() or with calling setWindowFilePath() after calling show(), I don't know what your problem is. I've made a working example so I hope this helps you in tracking down your problem:

#include <QApplication>
#include <QMainWindow>
#include <QPushButton>

class MyWindow : public QMainWindow
{
        Q_OBJECT

    public:

        MyWindow()
        {
            QPushButton* b = new QPushButton("Click me", this);
            connect(b, SIGNAL(clicked()), this, SLOT(click()));
        }

    private Q_SLOTS:

        void click()
        {
            setWindowFilePath("file.txt");
        }
};

int main(int argc, char* argv[])
{
    QApplication app(argc, argv);

    MyWindow w;
    w.show();

    return app.exec();
}

#include "main.moc"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top