首页 > 解决方案 > QtRemoteObjects 自动生成的副本标头抱怨未定义的 vtable

问题描述

开始使用 QtRO 并且生成的文件天生就抱怨 vtable:

#ifndef REP_REMOTEEXAMPLE_H
#define REP_REMOTEEXAMPLE_H

// This is an autogenerated file.
// Do not edit this file, any changes made will be lost the next time it is generated.

#include <QtCore/qobject.h>
#include <QtCore/qdatastream.h>
#include <QtCore/qvariant.h>
#include <QtCore/qmetatype.h>

#include <QtRemoteObjects/qremoteobjectnode.h>
#include <QtRemoteObjects/qremoteobjectpendingcall.h>
#include <QtRemoteObjects/qremoteobjectreplica.h>


class remoteExampleReplica : public QRemoteObjectReplica
{
    Q_OBJECT
    Q_CLASSINFO(QCLASSINFO_REMOTEOBJECT_TYPE, "remoteExample")
    Q_CLASSINFO(QCLASSINFO_REMOTEOBJECT_SIGNATURE, "5e40a606abdd95f709878d419edaa735fce25d0d")

public:
    remoteExampleReplica() : QRemoteObjectReplica() { initialize(); }
    static void registerMetatypes()
    {
        static bool initialized = false;
        if (initialized)
            return;
        initialized = true;
    }

private:
    remoteExampleReplica(QRemoteObjectNode *node, const QString &name = QString())
        : QRemoteObjectReplica(ConstructWithNode)
    {
        initializeNode(node, name);
    }

    void initialize() override
    {
        remoteExampleReplica::registerMetatypes();
        QVariantList properties;
        properties.reserve(0);
        setProperties(properties);
    }

public:
    virtual ~remoteExampleReplica() {}


Q_SIGNALS:
    void Close(QString a);
    void Open(QString b);

public Q_SLOTS:
    void onClosed()
    {
        static int __repc_index = remoteExampleReplica::staticMetaObject.indexOfSlot("onClosed()");
        QVariantList __repc_args;
        send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);
    }
    void onOpened()
    {
        static int __repc_index = remoteExampleReplica::staticMetaObject.indexOfSlot("onOpened()");
        QVariantList __repc_args;
        send(QMetaObject::InvokeMetaMethod, __repc_index, __repc_args);
    }

private:
    friend class QT_PREPEND_NAMESPACE(QRemoteObjectNode);
};

#if (QT_VERSION < QT_VERSION_CHECK(5, 5, 0))
#endif


QT_BEGIN_NAMESPACE
QT_END_NAMESPACE


#endif // REP_REMOTEEXAMPLE_H

问题指向私有构造函数。我只在我的代码中包含了副本标头,而没有真正使用远程对象作为测试运行。我已经阅读了很多关于 vtables 如何工作以及链接器抱怨 vtable 的内容,但在这种情况下,使用私有构造函数,我不确定问题是什么。
我错过了远程对象的实现吗?我没有正确生成文件吗?

.rep:

class remoteExample
{
  SIGNAL(Close(QString a));
  SIGNAL(Open(QString b));
  SLOT(onClosed());
  SLOT(onOpened());
};

标签: qtqt5qtremoteobjects

解决方案


推荐阅读