在包括QtNetwork时,我遇到了很多错误
While including QtNetwork I get a lot of errors
我使用带有内置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
依此类推
我发现这就是问题所在!!!1.我创建了单元测试,后来从项目中删除了它们,但没有t removed from folder as result lots of errors, which i presented here 2. I tried to include QtNetwork with < > , but it didn
t作品3。但当我qmake-project、qmake、nmake和生成的.pro文件中包含字符串QT+=网络项目时,已经成功编译了!!!
相关文章:
- 创建结构的数组时遇到分段错误
- 为什么我遇到分段错误?
- 这些是什么样的错误?即使我不在 Linux 上工作,我也遇到了 Linux 错误
- 为什么我在尝试模板时遇到视觉工作室C++错误
- 我在C++中遇到了这个奇怪的编译错误
- 我在 C++ 代码中遇到错误警告:控制到达非空函数 [-Wreturn 类型] 的末尾
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 我正在尝试一个傻瓜 C++ 练习,我遇到了一个错误,说类 'GraduateStudent' 没有任何名为 'advisor' 的字段
- 我在 ndk 中构建文件时遇到错误 android.mk
- 我在解决此错误时遇到问题.我正在努力在主函数中传递数组
- C++14 遇到奇怪的"use of deleted function"错误
- 在尝试使用递归查找集合子集的总数时,我遇到了分割错误
- 当我尝试在C++中对谷物进行序列化时,我遇到了一个奇怪的错误
- 我们在批处理模式下使用 G++ 时遇到错误
- 我不明白尝试使用字符串作为函数参数时遇到的错误
- 尝试通过多个函数移动数组,但遇到了我不知道如何修复的错误
- 我在c++中遇到了一个奇怪的错误,其中一个计算2个小整数加法的语句溢出到一个长值中
- 在visual Studio中构建代码时,我遇到错误,.h文件丢失
- 在Cython中使用C库时,我遇到了一个错误
- 错误:遇到非法内存访问