C ++ QtSoap不起作用:“未定义引用`QtSoapHttpTransport :: QtSoapHttpTransport(QObject *)`

时间:2013-12-26 18:12:03

标签: c++ qt soap qt-creator

我想让QtSoap正常工作。我正在使用这个库:https://qt.gitorious.org/qt-solutions/yjyong1217s-qt-solutions/source/4d83ff38ad836e507730034293d092df40b6d034:qtsoap

这是我的代码

#include "sevSOAP.h"

sevSOAP::sevSOAP(int number1, int number2, QObject *parent) : QObject(parent), http(this)
{
    this->number1 = number1;
    this->number2 = number2;

    http.setHost(host);
    // Or use just http.setHost(host)
    connect(&http, SIGNAL(responseReady()), this, SLOT(getResponse()));

}

void sevSOAP::sum()
{
    QtSoapMessage request;

    request.setMethod("sum");
    request.addMethodArgument("number1", "", number1);
    request.addMethodArgument("number2", "", number2);

    http.submitRequest(request, "/soma");
}

void sevSOAP::getResponse()
{
    const QtSoapMessage &message = http.getResponse();
    if (message.isFault()) {
        qDebug("Error: %s", qPrintable(message.faultString().toString()));
    }
    qDebug()<< message.returnValue().toString();
}

这是头文件:

#ifndef SEVSOAP_H
#define SEVSOAP_H

#include <qtsoap.h>

class sevSOAP : public QObject
{
    Q_OBJECT

    public:
        int number1;
        int number2;

        sevSOAP(int number1, int number2, QObject *parent = 0);
        void sum();

    private slots:
        void getResponse();

    private:
        QtSoapHttpTransport http;
};

#endif

无论我在做什么,它总是抛出这些编译错误:

C:\Projects/sevSOAP.cpp:3: undefined reference to `QtSoapHttpTransport::QtSoapHttpTransport(QObject*)'
C:\Projects/sevSOAP.cpp:8: undefined reference to `QtSoapHttpTransport::setHost(QString const&, bool, int)'
C:\Projects/sevSOAP.cpp:12: undefined reference to `QtSoapHttpTransport::~QtSoapHttpTransport()'
C:\Projects/sevSOAP.cpp:3: undefined reference to `QtSoapHttpTransport::QtSoapHttpTransport(QObject*)'
C:\Projects/sevSOAP.cpp:8: undefined reference to `QtSoapHttpTransport::setHost(QString const&, bool, int)'
C:\Projects/sevSOAP.cpp:12: undefined reference to `QtSoapHttpTransport::~QtSoapHttpTransport()'

我做错了什么?

编辑:

我试图让QtSOAP在QtCreator下运行:

#include <QApplication>
#include "sevSOAP.h"

sevSOAP::sevSOAP(QObject *parent) : QObject(parent), http(this)
{
    connect(&http, SIGNAL(responseReady()), this, SLOT(getResponse()));

    QtSoapMessage request;

    request.setMethod("TCKimlikNoDogrula");

    request.addMethodArgument("TCKimlikNo", "", "10000000146");
    request.addMethodArgument("Ad", "", "mustafa");
    request.addMethodArgument("Soyad", "", "atatürk");
    request.addMethodArgument("DogumYili", "", "1881");

    http.setHost("tckimlik.nvi.gov.tr", true);
    http.setAction("http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula");
    http.submitRequest(request, "/Service/KPSPublic.asmx?op=TCKimlikNoDogrula");

    qDebug("Looking up population of...");
}

void sevSOAP::getResponse()
{
    // Get a reference to the response message.
    const QtSoapMessage &message = http.getResponse();

    // Check if the response is a SOAP Fault message
    if (message.isFault()) {
        qDebug("Error: %s", message.faultString().value().toString().toLatin1().constData());
    }
    else {
        // Get the return value, and print the result.
        const QtSoapType &response = message.returnValue();
        qDebug("%s has a population of %s (last updated at %s)",
               response["Country"].value().toString().toLatin1().constData(),
               response["Pop"].value().toString().toLatin1().constData(),
               response["Date"].value().toString().toLatin1().constData());
    }
}

这是头文件:

#ifndef SEVSOAP_H
#define SEVSOAP_H

#include <qtsoap.h>

class sevSOAP : public QObject
{
    Q_OBJECT

    public:
        sevSOAP(QObject *parent = 0);

    private slots:
        void getResponse();

    private:
        QtSoapHttpTransport http;
};

#endif

我收到此错误输出:

mingw32-make[1]: Entering directory 'C:/Users/<user>/Projects/Release'
g++ -Wl,-s -Wl,-subsystem,windows -mthreads -o release/TCKimlikNoSorgulama.exe release/qtsoap.o release/main.o release/newForm.o release/sevSOAP.o release/moc_qtsoap.o release/moc_newForm.o release/moc_sevSOAP.o  -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmain -LC:\Developement\Qt\5.2.0\mingw48_32\lib -lQt5Widgets -lQt5Network -lQt5Xml -lQt5Gui -lQt5Core 
release/qtsoap.o:qtsoap.cpp:(.text+0x458): undefined reference to `_imp___ZTV10QtSoapType'
release/qtsoap.o:qtsoap.cpp:(.text+0x6b8): undefined reference to `_imp___ZTV16QtSoapSimpleType'
release/qtsoap.o:qtsoap.cpp:(.text+0x718): undefined reference to `_imp___ZTV11QtSoapArray'
release/qtsoap.o:qtsoap.cpp:(.text+0x10aa): undefined reference to `_imp___ZTV10QtSoapType'
release/qtsoap.o:qtsoap.cpp:(.text+0x162a): undefined reference to `_imp___ZTV10QtSoapType'
release/qtsoap.o:qtsoap.cpp:(.text+0x1732): undefined reference to `_imp___ZTV10QtSoapType'
release/qtsoap.o:qtsoap.cpp:(.text+0x2e5a): undefined reference to `_imp___ZTV11QtSoapArray'
release/qtsoap.o:qtsoap.cpp:(.text+0x2f4b): undefined reference to `_imp___ZTV11QtSoapArray'
release/qtsoap.o:qtsoap.cpp:(.text+0x3656): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x36eb): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x384c): undefined reference to `_imp___ZTV16QtSoapSimpleType'
release/qtsoap.o:qtsoap.cpp:(.text+0x388b): undefined reference to `_imp___ZTV16QtSoapSimpleType'
release/qtsoap.o:qtsoap.cpp:(.text+0x38dc): undefined reference to `_imp___ZTV16QtSoapSimpleType'
release/qtsoap.o:qtsoap.cpp:(.text+0x3940): undefined reference to `_imp___ZTV16QtSoapSimpleType'
release/qtsoap.o:qtsoap.cpp:(.text+0x399c): undefined reference to `_imp___ZTV16QtSoapSimpleType'
release/qtsoap.o:qtsoap.cpp:(.text+0x39f7): more undefined references to `_imp___ZTV16QtSoapSimpleType' follow
release/qtsoap.o:qtsoap.cpp:(.text+0x43e8): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x4694): undefined reference to `_imp___ZTV11QtSoapArray'
release/qtsoap.o:qtsoap.cpp:(.text+0x6d34): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x7137): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x736f): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x7c5f): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x7e7b): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0x8394): more undefined references to `_imp___ZTV12QtSoapStruct' follow
release/qtsoap.o:qtsoap.cpp:(.text+0xa38a): undefined reference to `_imp___ZTV21QtSoapTypeConstructorI12QtSoapStructE'
release/qtsoap.o:qtsoap.cpp:(.text+0xa3cd): undefined reference to `_imp___ZTV21QtSoapTypeConstructorI11QtSoapArrayE'
release/qtsoap.o:qtsoap.cpp:(.text+0xa408): undefined reference to `_imp___ZTV21QtSoapTypeConstructorI16QtSoapSimpleTypeE'
release/qtsoap.o:qtsoap.cpp:(.text+0xc430): undefined reference to `_imp___ZN19QtSoapHttpTransport13responseReadyEv'
release/qtsoap.o:qtsoap.cpp:(.text+0xc43b): undefined reference to `_imp___ZN19QtSoapHttpTransport13responseReadyERK13QtSoapMessage'
release/qtsoap.o:qtsoap.cpp:(.text+0xe4aa): undefined reference to `_imp___ZTV12QtSoapStruct'
release/qtsoap.o:qtsoap.cpp:(.text+0xe7aa): undefined reference to `_imp___ZTV19QtSoapHttpTransport'
release/qtsoap.o:qtsoap.cpp:(.text+0xe888): undefined reference to `_imp___ZTV19QtSoapHttpTransport'
release/qtsoap.o:qtsoap.cpp:(.text$_ZN25QtSoapTypeConstructorBaseD1Ev[__ZN25QtSoapTypeConstructorBaseD1Ev]+0xffff1681): undefined reference to `_imp___ZTV25QtSoapTypeConstructorBase'
Makefile.Release:88: recipe for target 'release/TCKimlikNoSorgulama.exe' failed
c:/developement/qt/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: release/qtsoap.o: bad reloc address 0x1 in section `.text$_ZN25QtSoapTypeConstructorBaseD1Ev[__ZN25QtSoapTypeConstructorBaseD1Ev]'
collect2.exe: error: ld returned 1 exit status

1 个答案:

答案 0 :(得分:1)

假设您在Qt软件中使用基于qmake的构建系统,则需要执行以下操作:

include(C:/path/to/qtsoap.pri)

在您的项目文件中。如果你看一下例子,这是必要的。所有这些都是这样做的。由于在./config && qmake-qt4 -r && make VERBOSE=1过程之后没有生成实际的库,因此他们将其作为假库进行操作。

如果你正在使用不同的构建系统,你需要复制内部的逻辑,但对于一个新手来说这是非常棘手的,主要是因为它使用了一些魔术内部像伪目标,没有文档的稀有,如TEMPLATE += fakelib,等人。

为了避免混淆:这个模块还没有被移植到Qt 5,因此如果不包含一些工作,你就无法让它工作。你需要暂时坚持使用Qt 4。