Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8997633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:54:57+00:00 2026-06-15T23:54:57+00:00

Hi fellow stack overflowers, I’m currently parsing a file which both contains text and

  • 0

Hi fellow stack overflowers,

I’m currently parsing a file which both contains text and binary data. Currently, I’m reading the file in following manner:

QTextStream in(&file);

int index = 0;
while(!in.atEnd()) {
    if (index==0) {
        QString line = in.readLine(); // parse file here
    } else {
        QByteArray raw_data(in.readAll().toAscii());
        data = new QByteArray(raw_data);
    }
    index++;
}

where data refers to the binary data I’m looking for. I’m not sure if this is what I want, since the QString is encoded into ascii and I have no idea if some bytes are lost.

I checked the documentation, and it recommends using a QDataStream. How can I combine both approaches, i.e. read lines with an encoding and also read the binary dump, after one line break?

Help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T23:54:57+00:00Added an answer on June 15, 2026 at 11:54 pm

    This will do what you want.

    QTextStream t(&in);
    QString line;
    QByteArray raw_data;
    if(!in.atEnd()) {line = t.readLine();}
    in.reset();
    int lineSize = line.toLocal8Bit().size() + 1;
    in.seek(lineSize);
    if(!in.atEnd())
    {
        int len = in.size() - lineSize;
        QDataStream d(&in);
        char *raw = new char[len]();
        d.readRawData(raw, len);
        raw_data = QByteArray(raw, len);
        delete raw;
    }
    

    PS: if file format is yours, it will be better to create file with QDataStream and write data with <<, read with >>. This way you can store QByteArray and QString in file without such problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following the advice of a fellow Stack Overflow user (on a previous question which
Dear fellow readers on Stack Overflow, I am currently working in CSS and I
I am trying to use a jQuery based Photo Stack which uses the following
Fellow StackOverflowers, we are building an iOS application that will record data which will
With some help from some fellow stack users, I currently have this: http://jsfiddle.net/wZETP/ The
With some help from fellow stack users I currently have this: http://jsfiddle.net/XRCvE/ I would
Hello fellow software developers. I want to distribute a C program which is scriptable
This is a follow up to link text about trying to remove the stack
Hello there fellow Stackers! I wonder if anybody could tell me what the following
Sup fellas, I am using the script that a fellow stack overflow user posted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.