我使用内置Qt的VS2010。我正在尝试实现客户端和服务器,使用UDP。 我从书Qt4编程GUI C ++中获取了示例。
实现主要基于Qt库QtNetwork
,但是当我包含它时,我会收到很多未知的错误,如:
Error 8 error C2653: 'System' : is not a class or namespace name ****\AssemblyInfo.cpp 3
Error 9 error C2871: 'Reflection' : a namespace with this name does not exist ****AssemblyInfo.cpp 3
我认为错误是该库QtNetwork
未正确包含的结果。
你能否告诉我如何解决这个问题?!
我试图通过自己的方式解决它,并采取以下行动:
在VS:Qt \ Qt项目设置中\添加网络库,然后qmake -project
,qmake
,nmake
在.pro文件中添加了字符串QT += network
,然后qmake -project
,qmake
,nmake
他们都未能应对陈述的问题。
#pragma once
#include <QWidget>
#include "QtNetwork"
#include <QtGui>
class QTimer;
class QUdpSocket;
class NetworkManagerServer : public QWidget
{
Q_OBJECT
public:
NetworkManagerServer(QWidget *parent = 0);
private slots:
void sendDatagramm();
private:
QUdpSocket* m_udpSocket;
QTimer* m_timer;
int m_messageNo;
};
#include "NetworkManagerServer.h"
NetworkManagerServer::NetworkManagerServer(QWidget *parent)
: QWidget(parent)
{
m_timer = new QTimer(this);
m_timer->start(2 * 1000);
m_udpSocket = new QUdpSocket(this);
m_messageNo = 1;
connect(m_timer, SIGNAL(timeout()), this, SLOT(broadcastDatagram()));
}
void NetworkManagerServer::sendDatagramm(void)
{
QByteArray datagramm;
QDataStream out (&datagramm, QIODevice::WriteOnly);
//out.setVersion(QDataStream::Qt_4_8);
out << "Hellow Qt::Network!";
m_udpSocket->writeDatagram(datagramm, QHostAddress::LocalHost,5824);
}
以下是我收到的错误列表:
Error 8 error C2653: 'System' : is not a class or namespace name ***\AssemblyInfo.cpp 3
Error 9 error C2871: 'Reflection' : a namespace with this name does not exist ***AssemblyInfo.cpp 3
Error 10 error C2653: 'System' : is not a class or namespace name ***AssemblyInfo.cpp 4
Error 11 error C2871: 'CompilerServices' : a namespace with this name does not exist ***AssemblyInfo.cpp 4
Error 12 error C2653: 'System' : is not a class or namespace name ***AssemblyInfo.cpp 5
Error 13 error C2871: 'InteropServices' : a namespace with this name does not exist ***AssemblyInfo.cpp 5
等等
答案 0 :(得分:0)
我发现那是问题! 1.我创建了单元测试,后来将它们从项目中删除,但是t removed from folder as result lots of errors, which i presented here 2. I tried to include QtNetwork with < > , but it didn
没有工作3.但是当我在qmake -project,qmake,nmake和生成的.pro文件中包含字符串QT + =网络项目已成功编译!