Hi,
Can any one help me how to open a text file & read values and display it in a textbox ?
Thanks...
Printable View
Hi,
Can any one help me how to open a text file & read values and display it in a textbox ?
Thanks...
Hey,
I am also from Bangalore.
So, For reading file you have to use the file handling. By using file handling, you can read the content of the text file and then set all the content on the textEdit. From that you can easily read the file. Use plainText to set the text.
Added after 10 minutes:
Try this code:---->
notepad.h
Code:
#ifndef NOTEPAD_H #define NOTEPAD_H #include <QWidget> #include<QFile> #include<QTextStream> namespace Ui { class Notepad; } { Q_OBJECT public: ~Notepad(); private: Ui::Notepad *ui; }; #endif // NOTEPAD_H
notepad.cpp
Code:
#include "notepad.h" #include "ui_notepad.h" ui(new Ui::Notepad) { ui->setupUi(this); QString str; stream>>str; file.close(); } ui->textEdit->setText(str); } Notepad::~Notepad() { delete ui; }
main.cpp
Code:
#include "notepad.h" #include "ui_notepad.h" ui(new Ui::Notepad) { ui->setupUi(this); QString str; stream>>str; file.close(); } ui->textEdit->setText(str); } Notepad::~Notepad() { delete ui; }
Hi,
Thankyou verymuch!!! it has worked out!!
notepad.ui
Attachment 7818