[英]Create COM object in Qt
我尝试创建一个COM对象,并从Qt中的对象获取接口。 因此,Qt充当COM客户端。 在我的示例中,COM服务器是CANoe COM服务器。
这是我尝试建立与CANoe的连接的Qt pro文件和interface.cpp文件的源代码:
专业档案:
# Add more folders to ship with the application, here
folder_01.source = qml/3com_interface
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
interface.cpp
# Installation path
# target.path =
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
HEADERS += \
CANoe.h \
interface.h
CONFIG += qaxcontainer
interface.cpp
#include "interface.h"
#include <QDebug>
#include "objbase.h"
#include "CANoe.h"
#include "windows.h"
#include "winnls.h"
#include "shobjidl.h"
#include "objidl.h"
#include "shlguid.h"
#include "strsafe.h"
Interface::Interface(QObject *parent) :
QObject(parent)
{
}
void Interface::trigger_slot(const QString &msg)
{
IApplication* pIApp;
HRESULT result;
result = CoInitialize(NULL);
CLSID clsid;
result = CLSIDFromProgID(L"CANoe.Application", &clsid);
if(SUCCEEDED(result))
{
qDebug() << "CLSID saved";
}
const IID IID_IApplication = __uuidof(IApplication);
result = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IApplication, (void**) &pIApp);
if(SUCCEEDED(result))
{
qDebug() << "Connection established";
}
}
当我尝试构建程序时,出现以下错误代码:对'_GUID const&_mingw_uuidof()'的未定义引用
有人知道如何在Qt和COM服务器之间创建COM接口吗? 我已经在互联网上搜索了几个小时,但没有找到任何解释。 仅用于通过使用ATL使用Visual Studio访问COM服务器。 但是我不能在Qt中使用ATL。
__uuid
为获取COM类的GUID提供了便利,但是任何其他方法也可以使用。 除此之外,您的代码应该可以工作。
该错误消息看起来像是MinGW链接错误(没有足够的信息来确定),表明您错过了MinGW COM库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.