QMetaEnum::fromType always -1 in debugger
-
I am successfully using
Q_ENUM
together withQMetaEnum::fromType
in my code. Everything works great and I can convert the enum strings to the actual enum values. However, as soon as I run the same code in the debugger,QMetaEnum::fromType
always returns -1 instead of the actual enum value. It works great when I am executing the code outside of the debugger (but still in debug mode, not release mode).Does anybody have any idea what causes this problem and more importantly: How to fix it?
I am using Qt 5.5.1 with MinGW 4.9.2 32-Bit and GDB 7.8 on Windows 10 64-Bit.
-
I am successfully using
Q_ENUM
together withQMetaEnum::fromType
in my code. Everything works great and I can convert the enum strings to the actual enum values. However, as soon as I run the same code in the debugger,QMetaEnum::fromType
always returns -1 instead of the actual enum value. It works great when I am executing the code outside of the debugger (but still in debug mode, not release mode).Does anybody have any idea what causes this problem and more importantly: How to fix it?
I am using Qt 5.5.1 with MinGW 4.9.2 32-Bit and GDB 7.8 on Windows 10 64-Bit.
Does anybody have any idea what causes this problem and more importantly: How to fix it?
Would you please provide some code that reproduces the issue. For example, how are you calling
QMetaEnum::fromType
how your class has been set up (the relevant parts). Do you have either theQ_OBJECT
orQ_GADGET
macros and so on. -
Does anybody have any idea what causes this problem and more importantly: How to fix it?
Would you please provide some code that reproduces the issue. For example, how are you calling
QMetaEnum::fromType
how your class has been set up (the relevant parts). Do you have either theQ_OBJECT
orQ_GADGET
macros and so on.Okay, I will write up a minimal test case that allows to reproduce the issue. Might take a few hours until I get to it, though.
My class usesQ_OBJECT
. -
Okay, I will write up a minimal test case that allows to reproduce the issue. Might take a few hours until I get to it, though.
My class usesQ_OBJECT
.Okay, I will write up a minimal test case that allows to reproduce the issue.
Well, I suggest to start with a few lines of code pasted here in the forum, and then if we couldn't deduce the problem from that you could go about preparing a whole example, how about that?
-
Okay, I will write up a minimal test case that allows to reproduce the issue.
Well, I suggest to start with a few lines of code pasted here in the forum, and then if we couldn't deduce the problem from that you could go about preparing a whole example, how about that?
Sure, whatever helps :)
This is the relevant code:class LibraryItem : public QObject { Q_OBJECT public: enum Type { TypeComponent = 0, TypePackage }; Q_ENUM(Type) ... static LibraryItem* factory() { const char* typeString = "TypeComponent"; int typeInt = QMetaEnum::fromType<LibraryItem::Type>().keyToValue(typeString); // typeInt is 0 when running the code outside of the debugger, -1 when running inside the debugger } ... };
-
Sure, whatever helps :)
This is the relevant code:class LibraryItem : public QObject { Q_OBJECT public: enum Type { TypeComponent = 0, TypePackage }; Q_ENUM(Type) ... static LibraryItem* factory() { const char* typeString = "TypeComponent"; int typeInt = QMetaEnum::fromType<LibraryItem::Type>().keyToValue(typeString); // typeInt is 0 when running the code outside of the debugger, -1 when running inside the debugger } ... };
@Joel-Bodenmann
Okay, this is a curious thing. I'd try some debugging of theQMetaEnum
in debug mode, to see what the problem might be; something like this:QMetaEnum myEnum = MetaEnum::fromType<LibraryItem::Type>(); if (!myEnum.isValid()) qDebug() << myEnum.name() << " is invalid with scope " << myEnum.scope(); for (qint32 i = 0, count = myEnum.keyCount(); i < count; i++) qDebug() << myEnum.key(i);
Try it out and see what is printed in the debug window.