English 中文(简体)
Help understanding QTest tutorials
原标题:

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[] = {
    "TestQStringtoUpper_data()toUpper()"
};

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.

最佳回答

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).

问题回答

暂无回答




相关问题
Qt: Do events get processed in order?

If I had a class A, where one of its functions does: void A::func() { emit first_signal(); emit second_signal(); } Assuming that a class B has 2 slots, one connected to first_signal, and the ...

How to determine how much free space on a drive in Qt?

I m using Qt and want a platform-independent way of getting the available free disk space. I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, ...

Drag & drop with .ui files

I m having big troubles with drag & drop. I ve created a new Qt Designer Form Class in which I have one QListWidget and one QWidget. Now I want to enable dragging & dropping between these two ...

Link errors on Snow Leopard

I creating a small desktop application using Qt and Poco on Mac OS X Snow Leopard. Qt works fine, but once I started linking with Poco I get the following warning: ld: warning: in /Developer/SDKs/...

Showing two windows in Qt4

My friend and I have each created parts of a GUI using Qt 4. They both work independently and I am trying to integrate his form with the my main window. As of now this is the code I am using to try ...

Qt equivalent of .NET data binding?

Is there an equivalent of .NET s data binding in Qt? I want to populate some combo boxes and other widgets with QStrings that refer to specific entities in my database. However, it would be cleaner ...

热门标签