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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:50:03+00:00 2026-06-17T06:50:03+00:00

I was thinking about writing method like this: QString getData() { QNetworkReply *reply =

  • 0

I was thinking about writing method like this:

QString getData() {
    QNetworkReply *reply = getReply();
    reply->deleteLater();
    return QString::fromUtf8(reply->readAll()).trimmed();
}

Is it safe?
If I’m forced to write this like this:

QString getData() {
    QNetworkReply *reply = getReply();
    QString result = QString::fromUtf8(reply->readAll()).trimmed();
    reply->deleteLater();
    return result;
}

I’m copping QString twice (am I?, once it’s put into result and second when returning it by value), which I wanted to avoid.

  • 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-17T06:50:04+00:00Added an answer on June 17, 2026 at 6:50 am

    From the deleteLater docs:

    Schedules this object for deletion.

    The object will be deleted when control returns to the event loop. If the event loop is not running when this function is called (e.g. deleteLater() is called on an object before QCoreApplication::exec()), the object will be deleted once the event loop is started.

    So what you are doing there is safe. Obviously handing out references or pointers to that object (or its members) that might be persisted is wrong. But if you’re returning copies, you’re fine.

    But what you’re doing might or might not do what you want to do. readAll doesn’t block, it returns the data currently available. Meaning that a single call to readAll might only read a partial response – unless you’ve ensured that all data has arrived through other means.

    Other things to note, from the docs:

    Note that entering and leaving a new event loop (e.g., by opening a modal dialog) will not perform the deferred deletion; for the object to be deleted, the control must return to the event loop from which deleteLater() was called.

    So the only thing to worry about when doing this type of thing would be calling functions that somehow re-enters the "current" event loop. But that won’t happen if that is done via QCoreApplication::processEvents:

    In event you are running a local loop which calls this function continuously, without an event loop, the DeferredDelete events will not be processed.

    So that’s covered too. The deferred deletion logic is pretty complex, but safe under normal circumstances. If you’re digging very deep into the Qt internals (or calling code that might do something fishy there), be defensive. But for normal code flow, deleteLater is safe as long as you don’t have dangling references (or pointers) that might persist.

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

Sidebar

Related Questions

I'm thinking about writing a very simple paint program. I would like a more
I'm thinking about writing a FLAC to ALAC and/or FLAC to AAC converter, probably
I'm thinking about writing a small application that will help me mass rename files.
I am thinking about writing a plugin for email application. It can be put
As a pet project, I was thinking about writing a program to migrate applications
I'm writing a simplified Pascal parser/interpreter and now I'm thinking about segmentation faults. I'm
Out of curiosity about reverse engineering, I am thinking of writing a simple program
So I've been thinking about PIMPL and stack allocation. I've been writing a library
I was thinking about how Regex.Match.Group wants to be dynamic: Regex.Match (...).Groups[Foo] would like
I am thinking about writing a windows service that will turn a certain functionality

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.