We help IT Professionals succeed at work.

Read Ascii data file -Qt

obad62 asked
I have this smaple of data for 12 record from the compleat file which has 41000 record so, what is the easy way to read the first 50 record as ascii data into Qt c++ programe. I have read there are Qfile and Qdata streame ...but which approperate. Also, are there any useful links or code for that.

Thanks in advanced

Watch Question

Hi Obad,

>>>I have this smaple of data for 12 record from the compleat file which has 41000
I am sorry I could not understand your question good, Can you please explain a bit, Do you mean that You have a data base which is having 41000 records? IS that in some RDBMS or DBMS like oracle or mySql sort of data base,? OR is that simple stored in some text file???
WHat do you mean by " I have sample of Data for 12 Records" ????
please explain


thanks for your responce
I have excel file which  has 41000 row I need to read 10 rows only  i used this code but nothing :

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main () {
string line;
ifstream myfile ("example.txt");
if (myfile.is_open())
while (! myfile.eof() )
getline (myfile,line);
cout << line << endl;

else cout << "Unable to open file";

return 0;
Well the code you are using is pure c++ code, it is at no point platform independent because you are not using Qt at all. I have written one small example using Qt which will prints the 10 record of any file in my example I am printing the main.cpp. Hope this will solve your purpose.
int main(int argc, char *argv[])
    QApplication a(argc, argv);
    QFile file("main.cpp");
     if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
         return 0;
      int recordCount=1;
     while (!file.atEnd()) {
         QByteArray line = file.readLine();
         qDebug()<<line<<recordCount++;// Print record and counter.

    return a.exec();


As I said to you problem in the file location