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

  • Home
  • SEARCH
  • 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 3486062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:59:00+00:00 2026-05-18T10:59:00+00:00

I am using QT Creator, created a console app. Everything is up to date.

  • 0

I am using QT Creator, created a console app. Everything is up to date. OS is Windows XP.

I have created a QString that holds some Hungarian chars. Most of the Hungarian chars do not require unicode but the chars that have double slashes for accents require unicode.

I try to write the QString contents to a file but my unicode chars lose their accents in the file. In other words, the unicode info is lost along the way.

My code is bellow.

#include <QtCore/QCoreApplication>
#include <QString>
#include <QTextStream>
#include <QDate>
#include <QFile>
using namespace std;


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

    QString szqLine = "NON-UnicodeIsOK: áéüúöóí NEED-Unicode: űő";
    //These are Hungarian chars and require unicode. Actually, only the u & o, each having double
    //slashes for eccents require unicode encoding.

    //Open file for writing unicode chars to.
    QFile file("out.txt");
    if ( !file.open(QIODevice::WriteOnly | QIODevice::Text) ){
        return 1;
    }

    //Stream the QString text to the file.
    QTextStream out(&file);
    out.setCodec("UTF-8");

    out << szqLine << endl;     //Use endl for flush.  Does not properly write ű and ő chars.
                                //Accents missing in file.

    file.close();               //Done with file.

    return app.exec();
}
  • 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-18T10:59:00+00:00Added an answer on May 18, 2026 at 10:59 am
    1. What is the encoding of your file? Using non-ascii encodings in source files often causes problems, at least when working cross-platform. I think MSVC has some problems there.

    2. QString foo = “unicode string” uses the implicit conversion from ascii to unicode, which will also cause problems. Always explicitely specify what encoding the literal uses, e.g. by wrapping the literal using QLatin1String() if it’s latin1:

      QString foo = QLatin1String(“some latin1 string”);

    or, utf-8, as it should be in your case, QString::fromUtf8():

    QString foo = QString::fromUtf8( "funny characters" );
    
    1. Before writing the string to a file (which is another source for possible errors, although your code looks correct), check if a qt widget (QLineEdit, for example) displays it correctly.

    To avoid such errors, I prefer to keep source files pure ascii, with english strings, and then translate them using Qt’s internationalization tools.

    Edit: Also see the accepted answer to this question about UTF-8 literals in MSVC 2008.

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

Sidebar

Related Questions

Using TortoiseSVN against VisualSVN I delete a source file that I should not have
I have a MYSQL table that holds events information. I need a mechanism that
I'm new to Qt and have been designing forms using Qt Creator. I've noticed
I have a project that uses SystemConfiguration.Framework. I've been using xcode, where adding the
Using online interfaces to a version control system is a nice way to have
Using ASP.NET MVC there are situations (such as form submission) that may require a
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C#, I need a class called User that has a username, password, active
I'm using Qt Creator on Ubuntu to develop C. Whenever I run with the
What is the most appropriate method to change the system date (on Windows) programmatically

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.