请选择 进入手机版 | 继续访问电脑版
  • 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c++ - qt 信号未定义引用错误

[复制链接]
菜鸟教程小白 发表于 2022-8-3 00:17:51 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我有一个类服务器,我为它创建了一个信号加入(QString 名称)。我在一个名为 join(QString name) 的函数中调用它,但是我收到错误

Server.o: In function Server::join(QString)': Server.cpp.text+0x48): undefined reference to Server::joined(QString)' collect2: ld returned 1 exit status



这是我的头文件的样子:
#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);
}



Best Answer-推荐答案


在你的类声明的开头,你应该有宏 Q_OBJECT并且一定要继承一些QObject后裔。

关于c++ - qt 信号未定义引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13409343/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap