Qt create 的体系结构 x86_64 的未定义符号

Undefined symbols for architecture x86_64 with Qt create

所以我试图将数据推送到游戏的数据库,但我一直收到“未定义的体系结构符号 x86_64”错误。我是 c++ 的新手(今天刚学,所以我很感激任何帮助,无论是修复我的错误还是我应该知道的任何代码礼仪。 这是数据库处理程序 .cpp:

#include "databasehandler.h"
#include "global_objects.hpp"
#include <QNetworkRequest>
#include <QDebug>
#include <QJsonDocument>
#include <QVariantMap>
#include <iostream>

DatabaseHandler::DatabaseHandler(QObject *parent) : QObject(parent)
{
    m_networkManager = new QNetworkAccessManager ( this );
    QVariantMap newUser;
    newUser[ "Stress" ] = QString::number(stressed);
    newUser[ "Sleep" ] = QString::number(tired);
    newUser[ "Hungry" ] = QString::number(hungry);
    newUser[ "Happy" ] = QString::number(happy);
    newUser[ "Grade" ] = QString::number(grade);
    newUser[ "Date" ] = "1/10/21";
    newUser[ "Gender" ] = QString::number(gender);
    newUser[ "Aid" ] = QString::number(help);
    QJsonDocument jsonDoc = QJsonDocument::fromVariant( newUser );

    QNetworkRequest newUserRequest( QUrl( "url.json"));
    newUserRequest.setHeader( QNetworkRequest::ContentTypeHeader, QString( "application/json" ));
    m_networkManager->post( newUserRequest, jsonDoc.toJson() );

}

DatabaseHandler::~DatabaseHandler()
{
    m_networkManager->deleteLater();
}

void DatabaseHandler::networkReplyReadyRead()
{
    qDebug() << m_networkReply->readAll();
}

全局对象.hpp:

#define GLOBAL_OBJECTS_HPP

extern int happy;
extern int happy;
extern int hungry;
extern int tired;
extern int stressed;
extern int gender;
extern bool help;
extern int grade;


#endif // GLOBAL_OBJECTS_HPP

全局对象.cpp:


namespace
{
    int happy;
    int hungry;
    int tired;
    int stressed;
    int gender;
    bool help;
    int grade;
}

和checkinapp.cpp:

#include "checkinapp.h"
#include "ui_checkinapp.h"
#include "databasehandler.h"
#include "global_objects.hpp"
#include <QNetworkRequest>
#include <QDebug>
#include <QJsonDocument>
#include <QVariantMap>
#include <iostream>

using namespace std;

checkinapp::checkinapp(QWidget *parent)
    : QMainWindow(parent),
    ui(new Ui::checkinapp)
{
    ui->setupUi(this);
}

checkinapp::~checkinapp()
{
    if(help == 0)
    {
        delete ui;
    }
    if(help == 1)
    {
        cout << "help";
    }
}

void checkinapp::on_happy_valueChanged(int value)
{
    happy = value;
}

void checkinapp::on_hungry_valueChanged(int value)
{
    hungry = value;
}


void checkinapp::on_sleep_valueChanged(int value)
{
    tired = value;
}


void checkinapp::on_stress_valueChanged(int value)
{
    stressed = value;
}


void checkinapp::on_male_toggled(bool checked)
{
    if(checked == true)
    {
        gender = 0;
    }
}

void checkinapp::on_female_toggled(bool checked)
{
    if(checked == true)
    {
        gender = 1;
    }
}

void checkinapp::on_other_toggled(bool checked)
{
    if(checked == true)
    {
        gender = 2;
    }
}

void checkinapp::on_help_toggled(bool checked)
{
    if(checked == true)
    {
        help = 1;
    }
}

错误说明如下:

error photo

.pro 文件:

QT += network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11 console

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    databasehandler.cpp \
    global_objects.cpp \
    main.cpp \
    checkinapp.cpp

HEADERS += \
    checkinapp.h \
    databasehandler.h \
    global_objects.hpp

FORMS += \
    checkinapp.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

正如 Botje 在评论中所说,从 globalvarible.cpp 中删除 namespace{} 修复了它。