So I'm attempting to push data to a database for a game but i keep receiving an "Undefined symbols for architecture x86_64" error. I am rather new to c (just learnt today so id appreciate any help, either towards fixing my error or any code etiquette i should know. Here is the database handler .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();
}
Global objects .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
global objects .cpp:
namespace
{
int happy;
int hungry;
int tired;
int stressed;
int gender;
bool help;
int grade;
}
and 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;
}
}
The error says the following:
.pro file:
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
CodePudding user response:
As Botje said in the comments dropping the namespace{}
from globalvarible.cpp fixed it.