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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:41:10+00:00 2026-05-14T01:41:10+00:00

When creating my own class in Qt I would like my variables in the

  • 0

When creating my own class in Qt I would like my variables in the class to have a standard/default value if I haven’t set them to anything. It would be perfect if this was possible to set in the h-file so I don’t have to do it in each instance method of my class. You can see what I want to do in the code below. In the example myBool would have the value of false and myInt the value of 0 when the object have been created. Is this possible at all?

In myclass.h:

class MyClass
{
    Q_OBJECT

public:
MyClass();
   ~MyClass();
    bool myBool = false; //I want to set myBool and myInt to a default/standard value
    int myInt = 0; 
};
  • 1 1 Answer
  • 2 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-14T01:41:11+00:00Added an answer on May 14, 2026 at 1:41 am

    Qt follows the rules of C++, and one rule is to use constructors to initialize your members.

    MyClass::MyClass() : myBool(false), myInt(0)
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating my own JavaScript Array-like object and I have methods that call closures.
I have a class which I would like to map as a component onto
I am currently in the process of creating my own blog and I have
I am considering creating my own website using Java and am trying to decide
I'm creating my own dictionary and I am having trouble implementing the TryGetValue function.
I am creating a user control in C# and I am adding my own
I'm getting ORA-01031: insufficient privileges when creating a package my own schema. Shouldn't I
Is there a generic way, without creating and managing your own CLR host, to
I'm creating a library to allow OCaml/Haskell-like algebraic data types and pattern matching. The
I am in the middle of creating my own custom MVC web framework for

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.