2012-11-16 35 views
14

私はシグナルを作成したクラスサーバを持っています(QString名)。私はしかし、私はエラーqtシグナル未定義の参照エラー

Server.oを得ている、参加(QStringの名)と呼ばれる機能で、それを呼び出す:関数の中でServer::join(QString)': Server.cpp:(.text+0x48): undefined reference to サーバーを:: collect2は(QStringの)」参加しました:ldは1つの終了ステータスを返し

これは私のヘッダファイルは、次のようになります。

#ifndef SERVER_H 
#define SERVER_H 

#include <QString> 
#include <mqueue.h> 
#include <QVector> 
#include <QStringList> 
#include "../src/messages.h" 

class Server 
{ 
public: 
    Server(); 
    void start(); 
private: 
    void join(QString name); 
    char buf[MSG_SIZE], msgSend[MSG_SIZE]; 
    QVector<mqd_t> mq_external; 
    QVector<QString> users; 
    mqd_t mq_central; 
    struct mq_attr attr; 


signals: 
    void joined(QString name); 

}; 

#endif // SERVER_H 

、これが私のcppファイルです:

#include "Server.h" 

using namespace std; 

Server::Server() 
{ 
} 

void Server::start(){ 

    attr.mq_maxmsg = 100; 
    attr.mq_msgsize = MSG_SIZE; 
    attr.mq_flags = 0; 

    mq_unlink(CENTRALBOX); 
    mq_central = mq_open(CENTRALBOX, O_RDONLY | O_CREAT, S_IRWXU, &attr); 
    while(1) 
    { 
     int tempMsgVal = mq_receive(mq_central, buf, MSG_SIZE, 0); 
     if(tempMsgVal != -1){ 
      QString tempS = buf; 
      QStringList tempSL = tempS.split(":"); 
      if(tempSL.size() == 2 && tempSL.at(0) == "started") 
      { 
       int x = 0; 
       bool exists = false; 
       for(int i = 0; i < mq_external.size(); i++) 
       { 
        x = QString::compare(tempSL[1], users.at(i), Qt::CaseInsensitive); 
        if(x == 0) 
        { 
         exists = true; 
         break; 
        } 
       } 

       if(!exists) 
       { 
        sprintf(buf,"joined"); 
        QString tempS1 = tempSL[1] + "new"; 
        QByteArray byteArray = tempS1.toUtf8(); 
        const char* tempr = byteArray.constData(); 
        mqd_t tempMQ = mq_open(tempr, O_RDWR); 
        int tempI = mq_send(tempMQ, buf, strlen(buf), 0); 
       } 
       else 
       { 
        sprintf(buf,"invalidname"); 
        QString tempS1 = tempSL[1] + "new"; 
        QByteArray byteArray = tempS1.toUtf8(); 
        const char* tempr = byteArray.constData(); 
        mqd_t tempMQ = mq_open(tempr, O_RDWR); 
        int tempI = mq_send(tempMQ, buf, strlen(buf), 0); 
       }//Endelse 
      }//Endif 
     }//Endif 

    }//Endwhile 
} 

void Server::join(QString name) 
{ 
    emit joined(name); 
} 

答えて

34

クラス宣言の冒頭に、マクロQ_OBJECTがあり、子孫のQObjectから継承されている必要があります。

+1

また、QObjectから継承すると思いますか? –

+2

は、私はそれをしなかったが、私は今 私のクラスの始まりを「サーバー用のvtableのために未定義の参照」追加のエラーを取得しています。この時間は、次のようになります。 クラスサーバー:公共QObjectを公共 { Q_OBJECT : 。 。 。 } 私もプロジェクトをきれいにして、すべてを再構築しました。 – Amre

+8

@Amre "make distclean"を実行し、 "qmake"をもう一度実行します。これにより、Makefileが再構築され、mocルールが最新のものになります。この場合、「クリーン」で十分ではありません。 –

3

this answerに記載されているもの以外にも、qmakeを必ず実行してください。すなわち:

Build > Run qmake 

これらのエラーを修正する必要があります。