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

The Archive Base Latest Questions

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

I am just curious. Let’s say for example I need to output a number

  • 0

I am just curious. Let’s say for example I need to output a number in the console.

The code would be:

#include <QDebug>
#include <QVariant>
#include <QString>

void displayNumber(quint8 number) {
    qDebug() << QVariant(number).toString();
    qDebug() << QString::number(number);
//or for example 
//  QLabel label; 
//  label.setText(QString::number(number));
//or 
//  label.setText(QVariant(number).toString());
}

Which would be better performance wise? I think the memory consumption is also different.
QVariant(number).toString() would mean that it stores a QVariant in the stack. Not sure about QString::number(), shouldn’t it just call the function(sure, the function has a QString return so it is allocated on the stack too and takes that space and that operations to allocated and unallocate it)?
Anyway, sizeof() gives me 16 Bytes for QVariant and 4 Bytes for QString.

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

    Of course the second variant is better.

    QString::number() is a static function that returns the desired string. When you use QVariant(number).toString(); you are first creating a QVariant, and than converting it into a desired string, so you make an extra and unnecessary variable of QVariant type.

    Also, you don’t need to transform the number to a string to output it with qDebug. qDebug() << 42; works fine.

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

Sidebar

Related Questions

Just curious how you would comment this line of code: string customerNm = customerNm.EndsWith(s)
I'm just curious what peoples' thoughts are on this topic. Let's say I have
I'm curious to know how Hibernate would handle the following situation. Let's say we
Just curious, is there a format string I can use to output something like
Just curious to find out exactly what problems I'll cause myself if I include
Just curious about a particular scenario of NAT. Let's suppose we have 4 computers
I'm just curious if unnecessary USINGs in my code slows down compiling of Visual
Let's say I have a Ruby object called Foo . This code will result
Let's say I have the following code: List<Category> categories = getCategories(); List<Category> unusedCategories =
For this example, I create an integer. int example = 0; Now let's say

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.