0

Qtが組み込まれたVS2010を使用しています。クライアントとサーバーを実装しようとしていますが、UDPが使用されています。私は本Qt4プログラミングGUIC+​​+から例を取りました。

実装は主に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が適切に含まれていなかった結果だと思います。この問題を解決する方法を教えてください。

私は自分の手段でそれを解決しようとし、次の行動を取りました:

  1. VSの場合:Qt \ Qtプロジェクト設定\ネットワークライブラリを追加してからqmake -project、、qmakenmake

  2. .proファイルに文字列を追加し、QT += network次にqmake -project、、qmakenmake

それらの両方は、述べられた問題に対処することができませんでした。

#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 に答える