Results 1 to 5 of 5

Thread: Saving a QtFile

  1. #1
    Join Date
    May 2010
    Posts
    30
    Qt products
    Qt4

    Default Saving a QtFile

    Hi

    I have a problem with the name of the file when saving it. when I open a new file , its name is untitled.txt and when I modify it the * appears but if I save the file normally there should be only the file name ( without * ) which is not the case and I don't understand where is the problem
    here is the function and at the end the title of my window.


    thanks


    Qt Code:
    1. void MainWindow::setCurrentFile(const QString &fileName)
    2. {
    3. curFile = fileName;
    4. setWindowFilePath(curFile);
    5.  
    6. QSettings settings;
    7. QStringList files = settings.value("recentFileList").toStringList();
    8. files.removeAll(fileName);
    9. files.prepend(fileName);
    10. while (files.size() > MaxRecentFiles)
    11. files.removeLast();
    12. settings.setValue("recentFileList", files);
    13.  
    14. foreach (QWidget *widget, QApplication::topLevelWidgets()) {
    15. MainWindow *mainWin = qobject_cast<MainWindow *>(widget);
    16. if (mainWin)
    17. mainWin->updateRecentFileActions();
    18. }
    19. QString shownName;
    20. if (curFile.isEmpty())
    21. shownName = "untitled.txt";
    22. else
    23. shownName = strippedName(curFile);
    24.  
    25. setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("my application name")));
    26. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Saving a QtFile

    setWindowTitle(tr("%1[*] - %2").arg(shownName).arg(tr("my application name")));
    you are explicitly showing the asterik '*' ,,,, arent you ??

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Saving a QtFile

    Quote Originally Posted by aamer4yu View Post
    you are explicitly showing the asterik '*' ,,,, arent you ??
    No, the syntax is right. But I don't see that you are using QWidget::setWindowModified() anywhere. That the * works, you have to tell if something have changed. So in your load function you have to call
    Qt Code:
    1. setWindowModified(false);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    May 2010
    Posts
    30
    Qt products
    Qt4

    Default Re: Saving a QtFile

    ok, thanks, so what do I have to do exactly to make it work ?
    Last edited by deeee; 26th May 2010 at 18:15.

  5. #5
    Join Date
    May 2010
    Posts
    30
    Qt products
    Qt4

    Default Re: Saving a QtFile

    Thanks so much for your answer. In fact I had to add this line

    Qt Code:
    1. setWindowModified(false);
    To copy to clipboard, switch view to plain text mode 

    in the functions save() and saveAs(). and now it works perfectly

Similar Threads

  1. Saving as XML
    By rakkar in forum Newbie
    Replies: 2
    Last Post: 30th October 2009, 17:17
  2. saving the state of the ui
    By zgulser in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2009, 12:17
  3. Saving QTextEdit
    By lixo1 in forum Qt Programming
    Replies: 5
    Last Post: 22nd March 2009, 16:51
  4. Saving settings to XML
    By arturo182 in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2009, 11:10
  5. Saving a QPainter
    By xgoan in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2006, 13:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.