这是我为在 Qt 应用程序中实现零拷贝而编写的程序,但出现以下错误:
//client.h
#ifndef CLIENT1_H
#define CLIENT1_H
#include <QObject>
#include <QString>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QtNetwork>
class Client: public QObject
{
Q_OBJECT
public:
Client(QObject* parent = 0);
~Client();
void start(QString address, quint16 port);
public slots:
void startTransfer();
private:
QTcpSocket client;
};
#endif // CLIENT1_H
//client.cpp
#include "client1.h"
#include <QtNetwork/QHostAddress>
#include <MSWSockDef.h>
#include <MSWSock.h>
Client::Client(QObject* parent): QObject(parent)
{
connect(&client, SIGNAL(connected()),
this, SLOT(startTransfer()));
}
Client::~Client()
{
client.close();
}
void Client::start(QString address, quint16 port)
{
QHostAddress addr(address);
client.connectToHost(addr, port);
}
void Client::startTransfer()
{
int TransmitFile( client,
hfile,
NULL,
NULL,
NULL,
NULL,
TF_USE_SYSTEM_THREAD
);
}
//main.cpp
#include <QCoreApplication>
#include <fstream>
#include <iostream>
#include "client1.h"
#include <QtNetwork/QtNetwork>
#include <Windows.h>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
HFILE hfile;
//Creates an instance of ofstream, and opens example.txt
ofstream a_file ( "example.txt" );
// Outputs to example.txt through a_file
a_file<<"This text will now be inside of example.txt";
// Close the file stream explicitly
hfile = a_file;
//a_file.close();
//hfile = a_file.open("example.txt");
//hfile = a_file.open("example.txt",ios_base::app);
Client client;
client.start("127.0.0.1", 8888);
return a.exec();
}
错误如下:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\MSWSock.
error: C2061: syntax error : identifier 'LPWSAMSG'
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\MSWSock.h
error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\MSWSock.h
error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
我知道transmitfile() api有错误,但是可以删除,上面的错误怎么办?`在这里输入代码?