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 8505173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:14:38+00:00 2026-06-11T02:14:38+00:00

The documentation says that QDataStream writes data in system independent way, but it says

  • 0

The documentation says that QDataStream writes data in system independent way, but it says nothing about QBuffer. I develop a program that saves data in a file like this:

QByteArray a;
QBuffer b(&a);
b.open(QIODevide::WriteOnly);
quint32 x = 1;
b.write((char*)&x, sizeof(x));
b.close();
QFile f(...);
f.open(QIODevide::WriteOnly);
f.write(a.constData(), a.size());
f.close();

, and i want this file can be read in any other OS (win, linux, Mac OS). Will this code work or i must use QDataStream instead?

  • 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-11T02:14:40+00:00Added an answer on June 11, 2026 at 2:14 am

    The QBuffer documentation says :

    The QBuffer class provides a QIODevice interface for a QByteArray.

    ie it is only a QByteArray underneath. On the other hand a QByteArray is portable because as long as you see the data as an array of byte and write one byte at a time you are fine. Your code will work:

    When you say

    I want this file to be read in any other OS

    Is your file used by your program only or will it be used by other applications in the system? QDataStream provides nicer functions for I\O and you may be still able to take advantage of it.


    It will be platform specific. x representation in memory depend on the endianess.It doesn’t occur in the QBuffer, but when you do :

    b.write((char*)&x, sizeof(x));
    

    If you are on machines of different endianess, you will obtain different values for the resulting array by doing

    char* data = &x;
    qDebug()<< data[0];
    qDebug()<< data[1];
    qDebug()<< data[2];
    qDebug()<< data[3];
    

    Take a look at the source code of QDataStream operator

    QDataStream &QDataStream::operator<<(qint32 i){
    
      CHECK_STREAM_WRITE_PRECOND(*this)
      if (!noswap) {
          i = qbswap(i);
      }
       if (dev->write((char *)&i, sizeof(qint32)) != sizeof(qint32))
           q_status = WriteFailed;
       return *this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The documentation says that execute() must be called from a UI thread. But, since
I have a question about __class__ in python. The documentation says that __class__ is
Documentation says that waypoints limit is 8 points. But I have to draw a
The documentation says that camel-spring-ws(v2.7.1) officially supports spring-ws 1.5.9, but doesn't mention spring-ws 2.0.2.RELEASE.
The documentation says that NSFileManager 's setUbiquitous method is the way to move a
Documentation says that waypoints limit is 8 points. But I have to calculate a
Java documentation says that a ServerSocket , x , that is listening on, say,
Official appengine documentation says that if we set threadsafe property to true in app.yaml
The play documentation says that « By default, [the Assets] controller provides caching, ETag,
The Android documentation says that best practices are to make two drawable directories -

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.