C++-QT QFile Open and Read File Example

  Summary:  This code shows how to open a file in a different directory and read all content of it.
 Qt Version:  4.7.4
Date Added: 2012-09-27

//main.cpp file
#include <QtGui>
#include <iostream>
int main(int argc, char **argv)
{
  QApplication app(argc,argv);
  
    QFile* file = new QFile();
    QDir::setCurrent("/home/user");
    file->setFileName("main.cpp");
    
    file->open(QIODevice::ReadWrite);
    
    QString strFile1(file->readAll());
    file->close();
    
    QTextEdit* edit = new QTextEdit();
    edit->setFixedSize(300,200);
    edit->setPlainText(strFile1);
    edit->setWindowTitle("QFile Open&Read File");
    edit->show();
    
  return app.exec();
}
Output :
QFile Open and Read File Example



Similar Examples
QFileDialog Remember Last Directory Example
QT Watch Directory Changes with QFileSystemWatcher Example
Make Symbolic Links with QFile

Browse Some Other Qt Examples
QLcdNumberQTimer
QPushButtonQMessageBox
QTabWidgetQtConcurrent
QLabelQList
QKeyEventQSlider
QFontDialogQSpinBox
QTableWidgetQTextBrowser
Qt StylesheetsQCheckBox
QComboBoxQCloseEvent
QProgressBarQProgressDialog
QTreeWidgetQSignalMapper

Want any example ? Feel free to tell us:
(Max. 2000 characters)
Please note that we do not guarantee to respond.Thanks.

C++
OpenSceneGraph
Fundamentals
QT
Boost
wxWidgets
Java
Python



Copyright 2011 - 2013 | All Rights Reserved
All trademarks are properties of their respective owners.
Contact| Privacy Policy| About Us