Question : Binary data

Hi ,
I need to read binary data , what is problem in my code . I find this error :
no maching function for call to 'QDataStream::readRowData()'
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
void Widget::on_pushButton_4_clicked()
{
    QFile file("p19f.bdf");
    if(!file.exists()){
         ui ->textBrowser->append("file is not exists");
    }
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
        ui ->textBrowser->append("file is not open");
        return ;
    }
    QDataStream in(&file);
    in.setVersion(QDataStream::Qt_4_3);
    
    unsigned int max_lines = 102;
    unsigned int lines_read = 0;
    while (!in.atEnd() && lines_read < max_lines)
    {
        QString content = in.readRawData();
        ui->textBrowser->append(content);
        lines_read++; // increase line counter
    }
    file.close();
}

Answer : Binary data

Hi obad62,

first there's no 'readRowData' in the code you posted so I guess it's a type and should be 'readRawData' - anyhow, QDataStream::readRawData is declared as 'int QDataStream::readRawData ( char * s, int len  )', so you have to pass a pointer to a 'char'-buffer and the size of the buffer. 'readRawData' then will fill the buffer with the loaded data and return the number of loaded bytes as 'int'.

BTW: You wrote you 'need to read binary data', but your code seems to be written to read string line by line from a text file. If you want to read a text file IMO you should use 'QTextStream' and its function 'readLine' instead of 'QDataStream'.

Hope that helps,

ZOPPO
Random Solutions  
 
programming4us programming4us