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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:39:24+00:00 2026-05-31T12:39:24+00:00

What is the difference between QString::number(0) and ((const char*) 0) ? I want to

  • 0

What is the difference between QString::number(0) and ((const char*) 0)?

I want to initialize a QString say phoneNumber to null. Will phoneNumber(QString::number(0)) and phoneNumber((const char*) 0) both work?

  • 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-31T12:39:25+00:00Added an answer on May 31, 2026 at 12:39 pm

    To create a null QString just default initialize it:

    QString phoneNumber;
    
    // or if you already have a QString variable and want to 'clear' it:
    
    phoneNumber = QString();
    

    Note that QString::number(0) is decidedly not null – it creates a QString with the value "0".

    You could also initialize the QString with a NULL pointer, but I wouldn’t recommend it unless you’re passing a pointer regardless of whether it’s NULL or not (i.e., it could sometimes point to a C string) since it’s unnecessary.

    You should also understand the following Qt docs:

    Distinction Between Null and Empty Strings

    For historical reasons, QString distinguishes between a null string
    and an empty string. A null string is a string that is initialized
    using QString‘s default constructor or by passing (const char *)0
    to the constructor. An empty string is any string with size 0. A null
    string is always empty, but an empty string isn’t necessarily null:

    QString().isNull();               // returns true
    QString().isEmpty();              // returns true
    
    QString("").isNull();             // returns false
    QString("").isEmpty();            // returns true
    
    QString("abc").isNull();          // returns false
    QString("abc").isEmpty();         // returns false
    

    All functions except isNull() treat null strings the same as empty
    strings. For example, toAscii().constData() returns a pointer to a
    '\0' character for a null string (not a null pointer), and
    QString() compares equal to QString(""). We recommend that you
    always use the isEmpty() function and avoid isNull().

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

Sidebar

Related Questions

The difference between Chr and Char when used in converting types is that one
Difference between Map and Properties as both have key-value pair.
Like the title 1.what's the difference between QString and QLatin1String?? 2.when and where do
Is there a performance difference between String.Replace(char, char) and String.Replace(string, string) when I just
The difference between to datetimes is the number of seconds between them. This seems
What is the difference between null and undefined in JavaScript?
I want to know difference between recursive function and using a stack in terms
Possible Duplicate: C - Difference between char var[] and char *var? I have written
Difference between a bus error and a segmentation fault? Can it happen that a
What is the difference between early and late binding?

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.