[Qt-interest] Q_ENUM registering Problem
Reece Dunn
msclrhd at googlemail.com
Thu Apr 15 10:23:27 CEST 2010
On 15 April 2010 09:13, Aaron Lewis <aaron.lewis1989 at gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 04/15/2010 03:53 PM, Denis Akhmetzyanov wrote:
>> Hi,
>> Is function QString fetchPic(MState state) in the mpainter class? Otherwise
>> you should use:
>
> fetchPic is part of mpainter class
>
> class mpainter : public QDialog {
> Q_OBJECT
> Q_ENUMS (MState)
>
> enum MState{ready,wait,lost};
>
> private:
> QString fetchPic(MState state);
> }
>
> In construct function of mpainter:
>
> I tried to call fetchPic:
> ===========================================
>
> QString aa = fetchPic(MState::ready);
>
> ===========================================
>
> Then i got errors like `MState is not a namespace or class'.
>
> Do i use the wrong way to call this function or put the enum declaration
> in the wrong place ?
>
> Appreciate any help ;-)
Anything defined in a class needs to be qualified by that class name
(it acts like a namespace scope). Therefore, you need to access MState
as mpainter::MState.
Enumeration values in C++ do not have the enumeration name as a scope
qualifier. Therefore, you don't access ready through
mpainter::MState::ready, but mpainter::ready.
Thus, you have:
QString aa = fetchPic(mpainter::ready);
Also, by default, anything declared in a class is private, so you may
get an error about not being able to access the enumeration or its
values. You therefore need something like this:
public:
enum MState{ready,wait,lost};
HTH,
- Reece
More information about the Qt-interest-old
mailing list