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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:22:53+00:00 2026-06-02T18:22:53+00:00

When using Qt, many functions take an argument like the flag Qt::LeftDockWidgetArea. Even though

  • 0

When using Qt, many functions take an argument like the flag Qt::LeftDockWidgetArea.

Even though I looked through the Qt sources I could not understand how to achieve
this naming behaviour. Is it general C++ or Qt specific?

Assume I have a class MyClass:

class MyClass {
    public:
        MyClass();
        void setFlag(???);
};

I want to call the setFlag method like this:

MyClass mc;
mc.setFlag(MyClass::flag1 | MyClass::flag2)

flag1 and flag2 should just be 0x01 & 0x02, is this an enum?
Where do I have to declare that?
And what is the argument of the method?

I’m sorry if this is obvious, but I don’t get it.

SOLUTION (from the answers)

Very good. From reading the answers below I added this:
(note that I didn’t really needed flags, just the numbers from an enum, this simplified it a lot)

namespace MyNames {
    typedef enum {
        FA = 0,
        FB = 1
    } Field;
}

class MyClass
{
    public:
        MyClass();
        char getField(MyNames::Field f) const;
};

This indeed allows the following calls (not):

mc.getField(MyNames::FA) //OK
mc.getField(1)           //not OK
  • 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-02T18:22:54+00:00Added an answer on June 2, 2026 at 6:22 pm

    You will find this (or something similar) in src\corelib\global\qnamespace.h:

    #ifndef Q_MOC_RUN
    namespace
    #else
    class Q_CORE_EXPORT
    #endif
    Qt {
    

    This usually becomes simply

    namespace Qt {
    

    To refer to a name declared inside this Qt namespace (such as LeftDockWidgetArea), you precede it with Qt::.

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

Sidebar

Related Questions

How could I generalise the function below to take N arguments? (Using call or
I've looked around, and did not find any information to create numpy.float64 using the
Helo, A library like jQuery is fully loaded and comes with many functions that
I am using include_once function in my code several times for many files my
We have a project that’s using many C++11 facilities, and we thought about this
I have a variable that I'm using many times in a class and as
I am returning some data from the database which is entered using many different
I want to share my session variables in PHP using many subdomains. I have
I have been in both situations: Creating too many custom Exceptions Using too many
I was browsing for an alternative to using so many shared_ptrs, and found an

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.