簡體   English   中英

在Qt中創建COM對象

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM