tags:

views:

310

answers:

1

In the tutorials for QTestLib, there are references to the files "testgui.moc" and "testqstring.moc" (one example can be found here: http://www.englishbreakfastnetwork.org/coverage/build/qt-copy/examples/qtestlib/tutorial3/.moc/debug-shared/testgui.moc). These include several pieces of information required to configure the tests. Unfortunately, the tutorials do not explain what this information is or how to change it. Specifically, I'm referring to these lines:

static const uint qt_meta_data_TestQString[] = {

 // content:
    2,       // revision
    0,       // classname
    0,    0, // classinfo
    2,   12, // methods
    0,    0, // properties
    0,    0, // enums/sets
    0,    0, // constructors

 // slots: signature, parameters, type, tag, flags
   13,   12,   12,   12, 0x08,
   28,   12,   12,   12, 0x08,

    0        // eod
};

static const char qt_meta_stringdata_TestQString[] = {
 "TestQString\0\0toUpper_data()\0toUpper()\0"
};

Now, based on my understanding of QT, the qt_meta_stringdata_TestQString variable is the class reference with the names of the methods appended -- something which might be done through something line METHOD(toUpper()), but I'm not sure if and how this is relevant for anything other than result formatting.

I'd like to know, in general, what is going on. The comment provided at the top of the files says that it has to do with "Meta object code", and that much seems obvious based on the methods it later overrides.

More importantly, however, I want to know how I can modify that qt_meta_data array so that it will allow me to call more functions and/or allow me to re-name the functions above to names of different length (switching the method names from toUpper to toApple seems to cause no problems, but changing them to toUppercase or toUp both causes the test application to fail to run as expected).

************************* UPDATE ****************************

There is already an accepted answer below, but I thought I should add this: The only reason those files were in the tutorials at all was because the tutorial authors decided NOT to have .h and .cpp files for their classes. They are otherwise useless.

+3  A: 

The code you posted is generated by Qt's meta object compiler (moc) from your header file. You shouldn't write/change the file yourself. Just write your class header and run moc on it (which is usually handled by the build system you use, qmake will do it by default).

Lukáš Lalinský
Thanks. Once again, QT is far simpler than I expected.
Christopher W. Allen-Poole