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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:34:23+00:00 2026-05-28T02:34:23+00:00

I am a student programmer currently designing a GUI for my company with Qt

  • 0

I am a student programmer currently designing a GUI for my company with Qt and I have a rather simple question that I just cant seem to find the answer to on the web. It seems like someone has had to of asked it before so if you know where the answer is Id be happy with a reference. My question is; can a Boolean datatype in c++ be handled using an if statement. So a bool value is either one or zero so can you do something like this

bool trueOrFalse()
{
    myclass temp;
    QString tempstr;
    double candidate;
    bool validate;

    tempstr = ui->tableWidgetInjectionLocations->item(i,9)->text();
    candidate = tempstr.toDouble(&validate);
                if(validate == true)
                {
                    temp.tempProperty = candidate;
                }
                else
                {
                    QMessageBox error;
                    error.setText("Error");
                    error.exec();
                }
    if (validate == true)
       {
       return true;
       }
    else
       {
       return false;
       }
}

What I am really looking for here is in the last section of this bool function. When I use return am I actually returning a value that this function would then hold or am I using a the keyword return inappropriately? Once validation has past Id like to be able to use the function to indicate whether or not to proceed in another function Please keep my criticism constructive please. As a student I am only interested in improving.

  • 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-28T02:34:24+00:00Added an answer on May 28, 2026 at 2:34 am

    The value you return using the return statement is literally returned whenever you call the function.

    So if you write this code somewhere else in your program:

    bool returnValue = trueOrFalse();
    

    then the returnValue variable will contain a Boolean value equivalent to whatever was returned by the trueOrFalse() function.

    The function itself doesn’t “hold” the value, the caller of the function defines a variable that will hold the value after the function call has completed.


    As for your second question, you are using the return statement correctly, but you can simplify your code in the trueOrFalse() function substantially. Instead of this:

       if (validate == true)
       {
           return true;
       }
       else
       {
           return false;
       }
    

    All you need is this:

    return validate;
    

    Because the validate local variable is already a bool!

    This removes the redundancy of checking a Boolean value against a Boolean constant (true), which prevents strange errors from creeping in and makes the code easier to read and understand.

    In fact, you can use this general pattern any time you’re working with Boolean values (bool). Rather than comparing them against the literal false or true, you can just write:

    if (validate)  // test for truth
    {
        // do whatever...
    }
    

    or

    if (!validate)  // test for falsity
    {
        // do whatever...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently a student programmer using Qt to build a GUI inteface at
I'm a student programmer and I'm doing some GUI programing for my company and
I'm a student programmer and I'm using Qt to create a Gui that gets
I am a student programmer using QT to develop and application for work. Currently
I am a student programmer using Qt to build a GUI interface fro my
I'm a student programmer and I am using Qt to build some GUI applications
I am a student programmer using Qt to develop a GUI application. I am
I am a student programmer using Qt to build a GUI for work. I
I am a student programmer and I am using Qt to build a GUI
I am student programmer and I am using Qt to develop a GUI interface

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.