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. Compare QVariable with Enum of DLL
QtWS25 Last Chance

Compare QVariable with Enum of DLL

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 320 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.
  • H Offline
    H Offline
    henrik2016
    wrote on last edited by
    #1

    I try to compare a QVariable of a QSignalSpy with a Enum in a test function. I found Q_ENUM_NS, but I got a linker error. I have rebuilt it and run qmake.

    Error Message: Undefined reference to CCS::staticMetaObject

    testopcua.cpp (most parts)

    Q_DECLARE_METATYPE(CCS::DataManagerState)
    
    using namespace ::testing;
    class TestOpcUa : public Test
    {
    public:
        TestOpcUa()
        {
            //.....
        }
    
        ~TestOpcUa()
        {
            delete _selectedConfValid;
            delete _opcUaObjectValid;
        }
    
    protected:
        MockOpcConf* _selectedConfValid = nullptr;
        OpcUa* _opcUaObjectValid = nullptr;
    };
    
    TEST_F(TestOpcUa, checkHandshake)
    {
        QSignalSpy readySpy(_opcUaObjectValid, SIGNAL(newManagerState(CCS::DataManagerState)));
        _opcUaObjectValid->connect();
        readySpy.wait();
        ASSERT_EQ(readySpy.count(), 1);
        ASSERT_EQ(readySpy.at(0).at(0).value<CCS::DataManagerState>(), CCS::DataManagerState::Ready); //Linker error
    }
    
    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
        testing::InitGoogleTest(&argc, argv);
        testing::InitGoogleMock(&argc, argv);
        return RUN_ALL_TESTS();
    }
    

    enums.h of DLL

    #include <QObject>
    
    namespace CCS
    {
        Q_NAMESPACE
    
        enum class DataManagerState
        {None, Configure, Ready, Active, Waiting, Stop};
        Q_ENUM_NS(DataManagerState)
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      since it's an enum simply use QVariant::tonInt() and do a static cast to the enum

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      0
      • H Offline
        H Offline
        henrik2016
        wrote on last edited by henrik2016
        #3

        @Christian-Ehrlicher thanks for your answer.

        If found a second solution here

        But to begin I had to add: qRegisterMetaTypeCCS::DataManagerState("state");

        Now it works.

        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