gpt4 book ai didi

c++ - 编译 QDbus 服务器应用程序时出错?

转载 作者:行者123 更新时间:2023-11-28 07:05:07 25 4
gpt4 key购买 nike

我是 Dbus 的新手,当然也是 QDBUS 的新手。我正在尝试从 nokia developer -QT 论坛复制示例。我有一个 xml 文件,通过它我生成了 qdbus 接口(interface) adaptor.cpp 和 .h。现在,我正在尝试包含此文件并进行构建。但是,我收到编译错误。你能请他修好这个吗?

(.text.startup+0x4c):-1: 错误:对 `MyDemo::MyDemo(QObject*)' 的 undefined reference

生成- adaptor.cpp

/*
* This file was generated by qdbusxml2cpp version 0.7
* Command line was: qdbusxml2cpp -c DemoIfAdaptor -a demoifadaptor.h:demoifadaptor.cpp com.nokia.Demo.xml
*
* qdbusxml2cpp is Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
*
* This is an auto-generated file.
* Do not edit! All changes made to it will be lost.
*/

#include "demoifadaptor.h"
#include <QtCore/QMetaObject>
#include <QtCore/QByteArray>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QStringList>
#include <QtCore/QVariant>

/*
* Implementation of adaptor class DemoIfAdaptor
*/

DemoIfAdaptor::DemoIfAdaptor(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
// constructor
setAutoRelaySignals(true);
}

DemoIfAdaptor::~DemoIfAdaptor()
{
// destructor
}

void DemoIfAdaptor::SayBye()
{
// handle method call com.nokia.Demo.SayBye
QMetaObject::invokeMethod(parent(), "SayBye");
}

void DemoIfAdaptor::SayHello(const QString &name, const QVariantMap &customdata)
{
// handle method call com.nokia.Demo.SayHello
QMetaObject::invokeMethod(parent(), "SayHello", Q_ARG(QString, name), Q_ARG(QVariantMap, customdata));
}

生成的 Adaptor.h

/*
* This file was generated by qdbusxml2cpp version 0.7
* Command line was: qdbusxml2cpp -c DemoIfAdaptor -a demoifadaptor.h:demoifadaptor.cpp com.nokia.Demo.xml
*
* qdbusxml2cpp is Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
*
* This is an auto-generated file.
* This file may have been hand-edited. Look for HAND-EDIT comments
* before re-generating it.
*/

#ifndef DEMOIFADAPTOR_H_1392803889
#define DEMOIFADAPTOR_H_1392803889

#include <QtCore/QObject>
#include <QtDBus/QtDBus>
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;

/*
* Adaptor class for interface com.nokia.Demo
*/
class DemoIfAdaptor: public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "com.nokia.Demo")
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"com.nokia.Demo\">\n"
" <method name=\"SayHello\">\n"
" <annotation value=\"QVariantMap\" name=\"com.trolltech.QtDBus.QtTypeName.In1\"/>\n"
" <arg direction=\"in\" type=\"s\" name=\"name\"/>\n"
" <arg direction=\"in\" type=\"a{sv}\" name=\"customdata\"/>\n"
" </method>\n"
" <method name=\"SayBye\"/>\n"
" <signal name=\"LateEvent\">\n"
" <arg direction=\"out\" type=\"s\" name=\"eventkind\"/>\n"
" </signal>\n"
" </interface>\n"
"")
public:
DemoIfAdaptor(QObject *parent);
virtual ~DemoIfAdaptor();

public: // PROPERTIES
public Q_SLOTS: // METHODS
void SayBye();
void SayHello(const QString &name, const QVariantMap &customdata);
Q_SIGNALS: // SIGNALS
void LateEvent(const QString &eventkind);
};

#endif

main.cpp 文件 -

#include <QtCore/QCoreApplication>
#include <QVariant>
#include <QDBusAbstractInterface>
#include "demoifadaptor.h"


class MyDemo : public QObject
{
Q_OBJECT
public:
explicit MyDemo(QObject *parent = 0);

public Q_SLOTS:
void SayBye();
void SayHello(const QString &name, const QVariantMap &customdata);
Q_SIGNALS:
void LateEvent(const QString &eventkind);

};


int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

MyDemo* demo = new MyDemo;

new DemoIfAdaptor(demo);

QDBusConnection connection = QDBusConnection::sessionBus();
bool ret = connection.registerService("com.nokia.Demo");
ret = connection.registerObject("/", demo);


return a.exec();
}

MyDemo.pro 文件。

#-------------------------------------------------
#
# Project created by QtCreator 2014-02-19T15:30:36
#
#-------------------------------------------------

QT += core

QT -= gui
QT += dbus

TARGET = MyDemo
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app


SOURCES += main.cpp \
demoifadaptor.cpp

HEADERS += \
demoifadaptor.h

最佳答案

您的示例提供了 explicit MyDemo(QObject *parent = 0); 的声明,但没有提供它的定义。因此链接器错误。其余的 MyDemo 方法也必须定义。

您还需要在源文件上运行元对象编译器以避免

"vtable..."

错误。尝试重新运行 qmake。任何时候添加对 Q_OBJECT 宏的新调用,都需要再次运行 qmake。您在评论中提到的 vtables 问题与此直接相关。

如果错误仍然存​​在,请在 main.cpp 的末尾添加 #include "MyDemo.moc"

关于c++ - 编译 QDbus 服务器应用程序时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21878296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com