문제

I added this line to my QTestLib test class:

QFETCH(MyType, value);

When trying to compile the test class, I get this error:

error: no member named 'qt_metatype_id' in 'QMetaTypeId<MyType>'
도움이 되었습니까?

해결책

When using QTest::addColumn and QFETCH for a type isn't built into Qt, you have to add this line:

Q_DECLARE_METATYPE(MyType);

It goes above the start of your test class. For example:

Q_DECLARE_METATYPE(MyType);

class MyTest : public QObject
{
    Q_OBJECT

private slots:

    void testSomething_data()
    {
        QTest::addColumn< MyType >("expectedValue");
        ...
    }
    void testSomething()
    {
        QFETCH(MyType, expectedValue);
        ...
}
};
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top