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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:36:14+00:00 2026-06-10T17:36:14+00:00

So, I’m making a text editor in Qt. And It does mostly very basic

  • 0

So, I’m making a text editor in Qt. And It does mostly very basic functions. New file, save, open, cut, copy, paste, bold, underline, italic, undo, and redo. But, when I bold, italicize, or underline text and then open the text file again It opens as plain text. As in if you open a file, bold some text, save it and then open it again it will be in plain text not bolded or anything. I have tried reading about how to make it work the way I want, but with no luck. My program can even create/open rich text files, but it works the exact same way. I understand that the way I have written the code makes it work the way it does. I just don’t know how to “fix” it.

Here are the blocks of code I have written that save and open files using the QFileDialog:

void WordWriteMain::on_actionOpen_File_triggered()
{
    QString fileName = QFileDialog::getOpenFileName(this,"Open a file","","Text (*.txt);;Rich Text (*.rtf)");
    QFile file(fileName);
    if(file.open(QIODevice::ReadOnly|QIODevice::Text)){
    ui->textBox->setText((file.readAll()));
    }
}

void WordWriteMain::on_actionSave_triggered()
{
    QString fileName = QFileDialog::getSaveFileName(this,"Open a file","","Text (*.txt);;Rich Text (*.rtf)");
    QFile file(fileName);
    if(file.open(QIODevice::WriteOnly|QIODevice::Text)){
        file.write(ui->textBox->toPlainText().toUtf8());
    }
}

Is what I’m trying to do even possible using QFileDialog? And like I said I understand the line file.write(ui->textBox->toPlainText().Utf8()); converts all of the text into plain text, but I don’t know how to make the save slot work without doing it that way.
As always thank you so much for dedicating your time to help me and for reading my question. If there is any more information needed I would be more than happy to provide it. EDIT: Also, I would like in the future to be able to add paragraph aligning so should I make my text editor strictly rich text?

  • 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-06-10T17:36:15+00:00Added an answer on June 10, 2026 at 5:36 pm

    Use toHtml() instead of toPlainText().
    When setting use setHtml() instead setText()

    Also use toAscii() instead of toUtf8() to do not loose user’s language code page.

    See: http://doc.qt.io/archives/qt-4.7/qtextedit.html

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

Sidebar

Related Questions

I have a reasonable size flat file database of text documents mostly saved in
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.