0

我使用带有内置 Qt 的 VS2010。我正在尝试实现客户端和服务器,使用 UDP。我以 Qt4 编程 GUI C++ 一书为例。

实现主要基于 Qt library 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未正确包含的结果。你能告诉我如何解决这个问题吗?!

我试图通过我的方式解决它,并采取以下措施:

  1. 在VS中:Qt\Qt项目设置\添加网络库,然后qmake -project,,,qmakenmake

  2. 在 .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

等等

4

1 回答 1

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 += 网络项目已经编译成功!!!

于 2012-07-17T15:06:18.813 回答