How can i get the text written in the QTextEdit during run time?



  • I want to save the text written in the QtextEdit by the user.



  • http://developer.qt.nokia.com/doc/qt-4.8/qtextedit.html#plainText-prop

    use the Acces function toPlainText (), which will return what you need.



  • but how can i save it during run time suppose i want to save it in file by clicking button?



  • You have to open a file, write into it. You have the QString from the function toPlainText().

    But the easiest way is using [[doc:QTextDocumentWriter]].



  • How to do this, is even handled in the most basic "Getting started Programming with Qt":/doc/qt-4.8/gettingstartedqt.html tutorial.

    And please, what is so hard to get a combination of textEdit->toHtml() and file->write() or textstream << string yourself? Is it really that hard?



  • [quote author="Volker" date="1325028679"]How to do this, is even handled in the most basic "Getting started Programming with Qt":/doc/qt-4.8/gettingstartedqt.html tutorial.

    And please, what is so hard to get a combination of textEdit->toHtml() and file->write() or textstream << string yourself? Is it really that hard?[/quote]

    No it is not hard but i have not seen that documentation before, otherwise i would not have asked it.



  • [quote author="pratik041" date="1325045378"]
    No it is not hard but i have not seen that documentation before, otherwise i would not have asked it.[/quote]

    Sorry, but you do not give the impression that you read documentation at all. A quick scan on [[Doc:QTextEdit]]'s list of member functions reveals all that secret sauce in no time.

    So it either is too hard for you to find out yourself, or you're plain stinking lazy and asking in the forum instead of doing your research yourself. I'm undecided which alternative is worse.

    Anyways, with your behavior, you're not going to make yourself friends here that are eager to help you, neither with your toy problems nor if you run into really interesting cases.



  • hello, i have used toplaintext method to get the text entered by the user and i save it in a file through wostream, but i get the commas and new lines entered by the user as , and \n etc which is not what i want..a relevant part of my code is below:

     key=ui->textEdit->toPlainText().toStdWString();
     json->AsObject()[L"guards"] = new JSONValue(key);
     std::wstring st = json->Stringify();
     myfile1 << st;
      myfile1.close();
    

    Please help as I am relatively new in C++ and need urgent help..



  • hello, i have used toplaintext method to get the text entered by the user and i save it in a file through wostream, but i get the commas and new lines entered by the user as , and \n etc which is not what i want..a relevant part of my code is below:

     key=ui->textEdit->toPlainText().toStdWString();
     json->AsObject()[L"guards"] = new JSONValue(key);
     std::wstring st = json->Stringify();
     myfile1 << st;
      myfile1.close();
    

    Please help as I am relatively new in C++ and need urgent help..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.