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 6351011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:55:15+00:00 2026-05-24T21:55:15+00:00

i am keeping a log of activities in my software using qtextedit. later when

  • 0

i am keeping a log of activities in my software using qtextedit. later when i want to save it as a text using toPlainText(), the resulting text file is a single line without any line breaks.
I start logging by plainText() and add subsequent additions using append().

void rocketscience::saveLog(){
QFile logFile;
QTextStream logOut;
QString logfName;

QSettings prevSet("us","fr");

    if (defaultDir.exists(prevSet.value("settings/logPath").toString()))
        logfName= QFileDialog::getSaveFileName(this,"Save File",fName,"Text (*.txt");


    if (logfName!=NULL){

    logFile.setFileName(logfName);
    logFile.open(QIODevice::WriteOnly);
    logOut.setDevice(&logFile);
    logOut<<ui.statusReport->toPlainText();
    logFile.close();
}

}

  • 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-24T21:55:17+00:00Added an answer on May 24, 2026 at 9:55 pm

    From the QTextStream class reference (that line is a bit hidden):

    Note: On Windows, all ‘\n’ characters are written as ‘\r\n’ if QTextStream’s device or string is opened using the QIODevice::Text flag.

    where ‘\n’ is the UNIX line ending and ‘\r\n’ is the Windows line ending (CR/LF).

    Remove the QTextStream initialisation at the start of your method and change the if statement to this:

    if (!logfName.isEmpty())
    {
        logFile.setFileName(logfName);
        logFile.open(QIODevice::WriteOnly);
        QTextStream logOut(&logFile, QIODevice::Text);
        logOut<<ui.statusReport->toPlainText();
        logFile.close(); 
    } 
    

    Also note how I changed the if condition. logfName is by default set to “”, I’m not sure if comparing to NULL will work. You’re better off using the QString::isEmpty() function

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

Sidebar

Related Questions

I have an application which is keeping a log of internally developed applications installed
console.log takes an unspecified number of arguments and dumps their content in a single
I've tried several methods of keeping a log of my day-to-day activity when writing
We have an application that uses MongoDB for log keeping. We run a pair
My users log in using an email address and their password using my custom
On my production site, I'm keeping the log for users when they visited my
Our logging class, when initialised, truncates the log file to 500,000 bytes. From then
My program is keeping a log for the user. If the log ever gets
I've got a huge log file (almost 6 GB) of a game server filled
I am dumping some log events into an XML file, every 5 minutes I

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.