如何告诉qmake在从dbus xml生成文件时包含标头
How to tell to qmake to include headers, when generating files from dbus xml?
TLDR:如何告诉qmake使用dbus xml描述生成文件,其中包括适当的标头?
完整示例和更多信息如下。
我的描述dbus接口的xml文件(custom.xml(如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-Bus Object Introspection 1.0//EN"
"http://standards.freedesktop.org/dbus/1.0/introspect.dtd">
<node>
<interface name="com.my.custom">
<method name="Get">
<arg type="a(sss)" name="info" direction="out"/>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="InfoArray"/>
</method>
</interface>
</node>
专业文件 (ex.pro( 如下所示:
TEMPLATE = lib
CONFIG += c++14 warn_on
QT += dbus
DBUS_INTERFACES += custom.xml
HEADERS += Info.hpp
SOURCES += Info.cpp
头文件 (Info.hpp(:
#ifndef INFO_HPP
#define INFO_HPP
#include <QtDBus/QtDBus>
#include <QtCore/QString>
#include <QtCore/QList>
#include <QtCore/QMetaType>
class Info
{
public:
friend const QDBusArgument &operator>>( const QDBusArgument &argument, Info& data );
friend QDBusArgument &operator<<( QDBusArgument &argument, const Info& data );
QString a;
QString b;
QString c;
};
typedef QList< Info > InfoArray;
Q_DECLARE_METATYPE(Info);
Q_DECLARE_METATYPE(InfoArray);
inline void registerCommType()
{
qDBusRegisterMetaType<Info>();
qDBusRegisterMetaType< InfoArray >();
}
#endif
和源文件 (信息.cpp(:
#include "Info.hpp"
QDBusArgument& operator<<( QDBusArgument& argument,
const Info& data )
{
argument.beginStructure();
argument << data.a;
argument << data.b;
argument << data.c;
argument.endStructure();
return argument;
}
const QDBusArgument& operator>>( const QDBusArgument& argument,
Info& data )
{
argument.beginStructure();
argument >> data.a;
argument >> data.b;
argument >> data.c;
argument.endStructure();
return argument;
}
当我尝试创建 Makefile 并构建库时,它失败了,因为生成的文件中的类型未知,因为生成的文件不包括Info.hpp
:
dejovivl@DEECLU52:~/workspace/qtdbus_custom$ qmake
Info: creating stash file /home/dejovivl/workspace/qtdbus_custom/.qmake.stash
dejovivl@DEECLU52:~/workspace/qtdbus_custom$ make
arm-pdm3-linux-gnueabi-g++ -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi -c -pipe -O2 -pipe -g -feliminate-unused-debug-types --sysroot=/opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi -O2 -std=gnu++1y -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_DBUS_LIB -DQT_CORE_LIB -I. -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5 -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5/QtGui -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5/QtDBus -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5/QtCore -I. -I/opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o Info.o Info.cpp
/opt/2017.12.6_2-cc/sysroots/x86_64-pdm3sdk-linux/usr/bin/qt5/qdbusxml2cpp -p custom_interface.h: custom.xml
/opt/2017.12.6_2-cc/sysroots/x86_64-pdm3sdk-linux/usr/bin/qt5/qdbusxml2cpp -i custom_interface.h -p :custom_interface.cpp custom.xml
arm-pdm3-linux-gnueabi-g++ -march=armv7-a -marm -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi -c -pipe -O2 -pipe -g -feliminate-unused-debug-types --sysroot=/opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi -O2 -std=gnu++1y -Wall -W -D_REENTRANT -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_DBUS_LIB -DQT_CORE_LIB -I. -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5 -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5/QtGui -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5/QtDBus -isystem /opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/include/qt5/QtCore -I. -I/opt/2017.12.6_2-cc/sysroots/cortexa9hf-neon-pdm3-linux-gnueabi/usr/lib/qt5/mkspecs/linux-oe-g++ -o custom_interface.o custom_interface.cpp
In file included from custom_interface.cpp:12:0:
custom_interface.h:39:30: error: ‘InfoArray’ was not declared in this scope
inline QDBusPendingReply<InfoArray> Get()
^~~~~~~~~
custom_interface.h:39:39: error: template argument 1 is invalid
inline QDBusPendingReply<InfoArray> Get()
^
custom_interface.h: In member function ‘int ComMyCustomInterface::Get()’:
custom_interface.h:42:77: error: cannot convert ‘QDBusPendingCall’ to ‘int’ in return
return asyncCallWithArgumentList(QStringLiteral("Get"), argumentList);
^
Makefile:663: recipe for target 'custom_interface.o' failed
make: *** [custom_interface.o] Error 1
我在 pro 文件中使用什么选项,因此生成的头文件包含 Info.hpp?
我知道qdbusxml2cpp
包含一个带有-i
选项的标题。如何告诉qmake去做?
这是QTBUG-11677。它已从Qt 5.0开始修复。有两种方法:
-
每个文件组 - 建议:
custom_interface.files = custom.xml custom_interface.header_flags = -i Info.hpp DBUS_INTERFACES += custom_interface
-
为所有接口头文件设置全局选项 - 这根本不好,因为它会用可能不相关的类型污染所有生成的接口头。
QDBUSXML2CPP_INTERFACE_HEADER_FLAGS += -i Info.hpp
另外 - 您不应该包括<QtModule/QClass>
,因为这会将项目配置错误推迟到链接时间。直接包含<QClass>
- 或者为了方便起见,整个模块<QtModule>
。如果文件无法编译,则生成文件已过时,您需要重新运行 qmake。
相关文章:
- 在CMake中使用find_package时,是否会显式包含标头
- GCC 包含标头(使用"-include")CMake 未检测到的更改
- 读取大文件(>2GB)(文本文件包含以太网数据)并通过不同参数随机访问数据的最佳方法是什么?
- C++文件包含多行
- CMake 如何强制third_party库将项目文件包含在当前项目源目录中?
- 使用预处理指令检查是否包含标头?
- QT 如何包含标头和 cpp 文件
- 是否可以链接到,包括和使用静态库,而无需额外包含标头/文件
- 如何告诉qmake在从dbus xml生成文件时包含标头
- 如何从平台SDK明确包含标头文件
- 在 main.cpp 以外的文件中包含标头时出现链接器错误
- 可以将标头文件包含在多个源文件中,而无需重复保护
- 有条件地将文件包含在C++标头中
- 如何在Visual Studio中的所有cpp文件中自动包含标头
- QT创建者错误地处理标头文件包含来自Directory
- 工具以确定最终如何包含标头文件
- .h文件应该是与外部函数的接口;如何在包含标头的.cc文件中进行定义
- 无法使用标头保护解决包含其自身的文件(包括标头)的错误
- 当我包含标头时,Gradle不会构建可执行文件
- 为什么带有包含标头的生成文件不起作用?