所以我試圖將資料推送到游戲的資料庫,但我一直收到“架構 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;
}
}
錯誤說明如下:
錯誤照片
。輪廓:
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
uj5u.com熱心網友回復:
正如 Botje 在評論中所說,namespace{}從 globalvarible.cpp 中洗掉修復了它。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/313878.html
