【问题标题】:What does the following function do?下面的函数有什么作用?
【发布时间】:2010-02-11 12:21:27
【问题描述】:

我正在寻找 Qt 对函数 QObject::qt_metacall(_c, _id, _a); 的实现,这是将给定函数名称转换为索引的地方。但我无法在他们的源代码中的任何地方找到函数实现。

int ssObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: readyToPrint(); break;
        case 1: readyToPrint1((*reinterpret_cast< int(*)>(_a[1]))); break;
               //''''

         }
    return _id;
   }

为什么会调用父类的qt_metacall

【问题讨论】:

    标签: qt implementation signals-slots


    【解决方案1】:

    你应该可以在某处找到 moc_qobject.cpp。它需要您构建 Qt,因为此文件是自动生成的,就像您自己的 moc 文件一样。

    这是来自我的构建(Windows 上的 4.6.1):

    int QObject::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
    {
        if (_id < 0)
            return _id;
        if (_c == QMetaObject::InvokeMetaMethod) {
            switch (_id) {
            case 0: destroyed((*reinterpret_cast< QObject*(*)>(_a[1]))); break;
            case 1: destroyed(); break;
            case 2: deleteLater(); break;
            case 3: d_func()->_q_reregisterTimers((*reinterpret_cast< void*(*)>(_a[1]))); break;
            default: ;
            }
            _id -= 4;
        }
    #ifndef QT_NO_PROPERTIES
          else if (_c == QMetaObject::ReadProperty) {
            void *_v = _a[0];
            switch (_id) {
            case 0: *reinterpret_cast< QString*>(_v) = objectName(); break;
            }
            _id -= 1;
        } else if (_c == QMetaObject::WriteProperty) {
            void *_v = _a[0];
            switch (_id) {
            case 0: setObjectName(*reinterpret_cast< QString*>(_v)); break;
            }
            _id -= 1;
        } else if (_c == QMetaObject::ResetProperty) {
            _id -= 1;
        } else if (_c == QMetaObject::QueryPropertyDesignable) {
            _id -= 1;
        } else if (_c == QMetaObject::QueryPropertyScriptable) {
            _id -= 1;
        } else if (_c == QMetaObject::QueryPropertyStored) {
            _id -= 1;
        } else if (_c == QMetaObject::QueryPropertyEditable) {
            _id -= 1;
        } else if (_c == QMetaObject::QueryPropertyUser) {
            _id -= 1;
        }
    #endif // QT_NO_PROPERTIES
        return _id;
    }
    

    【讨论】:

    • 我贴的这段代码来自 moc_ssObject.cpp
    • Doh.. 对不起。我已经更新了我的答案并发布了我最近的 Qt 版本中的代码。
    【解决方案2】:

    它使用列表 _a 中的参数调用类 _c 的索引为 _id 的方法。

    我相信实现是moc生成的,所以它不在任何源码树中。

    【讨论】:

      猜你喜欢
      • 2023-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-05
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多