Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:09:33+00:00 2026-05-31T22:09:33+00:00

I want the user to be able to enter a name for a file

  • 0

I want the user to be able to enter a name for a file that will be saved as an xml file. Currently on Windows and Mac if you enter “test” as the file name it will automatically add “.xml” which is what I want. Unfortunately when testing a Linux build I found that entering a file name without an extension would save as an ordinary file. The user has to specify the extension in the file string (i.e “test.xml”) in order for it to save in the correct format.

The code I’m using is below. Is this a Qt bug or is there a way to specify in Qt that it should add an extension if one wasn’t found?

// Get value for "dir". If the setting doesn't exist then use
// the the path in "defaultsave.directory"
QString prevPath = prevValues.value("dir", QString::fromStdString(
  ConfigService::Instance().getString("defaultsave.directory"))).toString();

QString filter;
filter.append("Files (*.xml)");
filter += ";;AllFiles (*.*)";
QString groupingFile = QFileDialog::getSaveFileName(this, "Save Grouping file as", prevPath, filter);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:09:35+00:00Added an answer on May 31, 2026 at 10:09 pm

    Since you get the string from the dialog with getSaveFileName, you can just do something like:

    if (!groupingFile.endsWith(".xml"))
        groupingFile += ".xml";
    

    It’s probably different on Linux because of this little snippet buried in the documentation for getSaveFileName:

    On Windows, Mac OS X and Symbian^3, this static function will use the native file dialog and not a QFileDialog.

    In other words, it’s the adding of the prefix (done by the native dialogs) that is aberrant, at least in terms of Qt.


    As pointed out in the comments, you may find an issue with this solution in that the dialog box itself won’t notify you if you type in xyzzy manually and the file xyzzy.xml already exists (assuming the native dialogs do this – I haven’t actually checked). If you want that behaviour, you’ll need to implement it as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, so I want the user to be able to enter every character from
I have a MovieClip that I want the user to be able to drag
I have a dictionary of strings that i want the user to be able
I want to prompt the user for a directory name, and have them able
Ok, I want the user to be able to press enter to initiate a
I'd like the user to be able to enter the MAC of a computer
I am creating a Java desktop application where the user will enter his name
I want the user to be able to make some preferences like colors, prefered
I want the user to be able to see my application in the menu
I want the user to be able to select an option, which would change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.