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

  • Home
  • SEARCH
  • 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 6580613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:03:01+00:00 2026-05-25T16:03:01+00:00

These 2 functions are my attempt to serialize a QVector. Unfortunally I can’t use

  • 0

These 2 functions are my attempt to serialize a QVector. Unfortunally I can’t use QDataStream because my boss requires that the implementation is Qt independent and QDataStream prepends a header. So the problem is the vector returned by the function binToVector returns a size equals to 0, but if the elements are printed they are equal to the original vector. Why the size returned is zero if the vector has elements equal to the original? These serialization functions are ok? I cannot use boost neither Qt functions to implement it, only C++;

QByteArray vectorToBin(const QVector<qint32> & vec)
{
  QByteArray result;
  foreach(quint32 e, vec) {
    char *src = reinterpret_cast<char*>(&e);
    result.append(src, sizeof(qint32));
  }
  return result;
}

QVector<qint32> binToVector(const QByteArray & bytes) 
{
  int size = sizeof(qint32);
  QVector<qint32> result;
  result.reserve(bytes.count()/size);
  int j=0;
  for(int i=0; i<bytes.count(); i+=size) {
    memcpy(&result[j++], bytes.constData()+i, size);
  }
  return result;
}
  • 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-05-25T16:03:02+00:00Added an answer on May 25, 2026 at 4:03 pm

    You’re calling QVector::reserve, which allocates memory for the class to use as storage, but doesn’t actually change the number of real elements in the container. For that, you need QVector::resize. The standard C++ vector class works the same way. Reserving space in advance ensures that repeated future calls to append don’t have to re-allocate the container’s storage all the time.

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

Sidebar

Related Questions

Can someone clearly explain me how these functions of heap sort are working?? void
Is there something like serialize/unserialize PHP functions in jQuery? These functions return a string
I have two functions that generate DOM elements. They both attempt to create the
These functions may be hard to fit into a specific class, what's the best
This is the example code, I'm using these functions for a program, but scanf
Currently, I'm setting DecimalSeparator to a '.' in each procedure which uses these functions.
I do not understand the following example, let's say I have these functions: #
I think its common for database tests to include CRUD operations. So these functions
I have these two functions (with Point2D & LineVector (has 2 Point2D member variables)
Please help to replace these jQuery functions with Prototype ones: $(button,input,label,select,textarea).bind('mouseover mouseout', function(){$(this).toggleClass('hover')}); $(button,input,select,textarea).bind('focus

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.