how can I get setWindowFilePath() to work?

I can't seem to get setWindowFilePath to work in any of my projects.  The value is stored and can be retrieved, but it never shows up in the title bar of my app.  It does work correctly in a sample app I downloaded, but I can't find what they do differently.  Anyway, here's a simple app I created to demonstrate the problem.  I pasted the code from the 3 files, mainwin.h, main.cpp, and mainwin.cpp below.

Any ideas?  I'm using Qt 4.6.3 on Windows 7, with the MS compiler.

#ifndef MAINWIN_H
#define MAINWIN_H

#include <QMainWindow>

class mainwin : public QMainWindow
{
    Q_OBJECT
public:
    explicit mainwin(QWidget *parent = 0);

signals:

public slots:

};

#endif // MAINWIN_H

#include "mainwin.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.setApplicationName("my test");
    app.setOrganizationName("NTFMO");
    mainwin window;
    window.show();
    return app.exec();
}

#include "mainwin.h"

mainwin::mainwin(QWidget *parent) :
    QMainWindow(parent)
{
  setWindowFilePath("C:\asdf.txt");

}

Open in new window

davidbursonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

irfan_omairCommented:
I dont see any problem with this code. But can you check with backward slash and forward slash as Qt takes it different and it converts forward slash to unix standard .
OR, can you try putting double slash like  setWindowFilePath("C:\\asdf.txt");
OR  setWindowFilePath("C:/asdf.txt");
0
davidbursonAuthor Commented:
none of those worked.  Is there some setting somewhere that needs to be activated, or something like that?

The value does get set, it just isn't being displayed in the title bar.  For example, I can add:
qDebug() << windowFilePath();

(and #include <QDebug> at the top of mainwin.h)

and whatever I pass into setWindowFilePath is printed out in my Application Output window.  So it is setting the value.  But what do I have to do to get it to display the value in the title bar?
0
irfan_omairCommented:
Can you check is that file name which you are supplying really exists in that path?
sounds strange if it exists and still that does not work, can you try adding  this setWindowModified(false);
If this does not work too, then I will say add manual code which does this
QString shownName;
if (fileName.isEmpty())
shownName = "untitled.txt";
else
shownName = QFileInfo(fileName).fileName();
setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("Rich Text")));
setWindowModified(false);

0
davidbursonAuthor Commented:
It appears from further research that setWindowFilePath() doesn't work when called from the constructor.  Instead, you have to use QTimer::singleShot to call a slot.  In the slot, you can use setWindowFilePath.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.