Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMetaEnum::fromType always -1 in debugger
QtWS25 Last Chance

QMetaEnum::fromType always -1 in debugger

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmetaenumqenum
6 Posts 2 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Joel BodenmannJ Offline
    Joel BodenmannJ Offline
    Joel Bodenmann
    wrote on last edited by
    #1

    I am successfully using Q_ENUM together with QMetaEnum::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.

    Industrial process automation software: https://simulton.com
    Embedded Graphics & GUI library: https://ugfx.io

    kshegunovK 1 Reply Last reply
    0
    • Joel BodenmannJ Joel Bodenmann

      I am successfully using Q_ENUM together with QMetaEnum::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.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      @Joel-Bodenmann

      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 the Q_OBJECT or Q_GADGET macros and so on.

      Read and abide by the Qt Code of Conduct

      Joel BodenmannJ 1 Reply Last reply
      0
      • kshegunovK kshegunov

        @Joel-Bodenmann

        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 the Q_OBJECT or Q_GADGET macros and so on.

        Joel BodenmannJ Offline
        Joel BodenmannJ Offline
        Joel Bodenmann
        wrote on last edited by
        #3

        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 uses Q_OBJECT.

        Industrial process automation software: https://simulton.com
        Embedded Graphics & GUI library: https://ugfx.io

        kshegunovK 1 Reply Last reply
        0
        • Joel BodenmannJ Joel Bodenmann

          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 uses Q_OBJECT.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Joel-Bodenmann

          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?

          Read and abide by the Qt Code of Conduct

          Joel BodenmannJ 1 Reply Last reply
          0
          • kshegunovK kshegunov

            @Joel-Bodenmann

            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?

            Joel BodenmannJ Offline
            Joel BodenmannJ Offline
            Joel Bodenmann
            wrote on last edited by Joel Bodenmann
            #5

            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
            	}
            
                ...
            };
            

            Industrial process automation software: https://simulton.com
            Embedded Graphics & GUI library: https://ugfx.io

            kshegunovK 1 Reply Last reply
            0
            • Joel BodenmannJ Joel Bodenmann

              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
              	}
              
                  ...
              };
              
              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              @Joel-Bodenmann
              Okay, this is a curious thing. I'd try some debugging of the QMetaEnum 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.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved