?
Solved

how can I get setWindowFilePath() to work?

Posted on 2010-08-16
4
Medium Priority
?
901 Views
Last Modified: 2013-11-23
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

0
Comment
Question by:davidburson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:irfan_omair
ID: 33447744
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
 

Author Comment

by:davidburson
ID: 33447828
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
 
LVL 7

Expert Comment

by:irfan_omair
ID: 33448009
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
 

Accepted Solution

by:
davidburson earned 0 total points
ID: 33448091
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question