2

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

インターフェイス.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";
    }

}

プログラムをビルドしようとすると、次のエラー コードが表示されます: undefined reference to '_GUID const&_mingw_uuidof()'

Qt と COM サーバー間の COM インターフェイスを作成する方法を知っている人はいますか? インターネットで何時間も検索しましたが、説明が見つかりません。ATL を使用して Visual Studio で COM サーバーにアクセスする場合のみ。しかし、Qt で ATL を使用できません。

4

1 に答える 1

1

__uuidCOM クラスの GUID を取得するのに便利ですが、他の方法でも機能します。それ以外は、コードが機能するはずです。

エラー メッセージは、MinGW リンク エラーのように見えます (確認するには十分な情報がありません)。これは、MinGW COM ライブラリが見つからないことを示唆しています。

于 2013-12-11T10:28:53.897 に答える