Open a Particular text document in TextEdit box
-
I've working in an application where there is a multiple windows.In 2nd window there is text edit box.
when i jump from 1st window to the 2nd i want the textedit to open a text document from a certain directory.How can i do this?
I am new to Qt and devolopment.So,a less complicated method will be appreciated. -
Hi,
Can you explain the workflow more precisely ? You likely don't want to have the text reloaded each time you change to the second window, yes ?
How do you get to that second window ? -
Hi,
Can you explain the workflow more precisely ? You likely don't want to have the text reloaded each time you change to the second window, yes ?
How do you get to that second window ?@SGaist,it's a diary app, the first window is a welcome page.a push button should make the jump to the 2nd page which is the writing page.
Before jump it will get the system date and check if there is a text file named after it,if there is it will open it in the textedit box and if there is not it will create a text document and open it in the textedit -
Then the file handling part should happen before showing the other widget.
You should also think about the saving part.
-
Then the file handling part should happen before showing the other widget.
You should also think about the saving part.
@SGaist I've done all those part,I'm stuck in the part where I connect the text document with the TextEdit Box.If anyone can show me me an example it'll be great.
-
What do you mean by connect ?
-
Hi
do you mean to load the text document ?QFile file("FileName.txt"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); edit->setPlainText( stream.readAll() ); }
-
Hi
do you mean to load the text document ?QFile file("FileName.txt"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); edit->setPlainText( stream.readAll() ); }
@mrjj The Text document will already exist.When i click a push button it should open the file and show the texts in the TextEdit box in the next page also the textedit box should work as a notepad for the text file,which means i can keep editing the text file and save.
I've tired your example,it's not showing anything :( -
@mrjj The Text document will already exist.When i click a push button it should open the file and show the texts in the TextEdit box in the next page also the textedit box should work as a notepad for the text file,which means i can keep editing the text file and save.
I've tired your example,it's not showing anything :(Hi
If it shows nothing in your textEdit then maybe the path is not correct ?add a check and see.
QFile file("FileName.txt"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); edit->setPlainText( stream.readAll() ); } else QMessageBox::warning(this, "title", "file open error:" + file.errorString() );
-
Hi
If it shows nothing in your textEdit then maybe the path is not correct ?add a check and see.
QFile file("FileName.txt"); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); edit->setPlainText( stream.readAll() ); } else QMessageBox::warning(this, "title", "file open error:" + file.errorString() );
This post is deleted!