I keep getting the following error: Undefined symbols for architecture x86_64: "checkinapp::myOnFinishedSlot(QNetworkReply*)", referenced from: "checkinapp::qt_static_metacall(QObject*,QMetaObject::Call,int,void**) in moc_checkinapp.o
I have looked through several times and can't figure out where I have gone wrong. (Im new to c so im sorry i probably missed something obvious). Any help is appreciated :)
Here is my class:
class checkinapp : public QMainWindow
{
Q_OBJECT
public:
checkinapp(QWidget *parent = nullptr);
~checkinapp();
void databasehandler(QWidget *parent = nullptr);
int stressed;
int happy;
int hungry;
int tired;
int gender;
bool help;
int grade;
bool submitted;
void post()
{
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/User.jason"));
newUserRequest.setHeader( QNetworkRequest::ContentTypeHeader, QString( "application/json" ));
connect(m_networkManager, &QNetworkManager::finished, this, &checkinapp::myOnFinishSlot); // the error is here
m_networkManager->post( newUserRequest, jsonDoc.toJson() );
}
void exit()
{
QApplication::quit();
}
public slots:
void myOnFinishSlot(QNetworkReply* x) { exit(); }
private slots:
void on_happy_valueChanged(int value);
void on_hungry_valueChanged(int value);
void on_sleep_valueChanged(int value);
void on_stress_valueChanged(int value);
void on_male_toggled(bool checked);
void on_female_toggled(bool checked);
void on_other_toggled(bool checked);
void on_help_toggled(bool checked);
void on_pushButton_clicked();
private:
Ui::checkinapp *ui;
QNetworkAccessManager * m_networkManager;
QNetworkReply * m_networkReply;
};
CodePudding user response:
Your declaration
void myOnFinishSlot(QNetworkReply* x)
Does not match your definition:
void myOnFinishSlot()
You effectively defined two methods with different overloads.
Either merge the definition and declaration:
public slots:
void myOnFinishSlot(QNetworkReply* x) { exit(); }
or move the definition outside of the class
block:
void checkinapp::myOnFinishSlot(QNetworkReply* x) { exit(); }
Additionally, don't use the SIGNAL/SLOT notation, since it leads to hard-to-debug errors at runtime. Your connect
call should be:
connect(m_networkManager, &QNetworkAccessManager::finished, this, &checkinapp::myOnFinishSlot);