0

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;
};

1 Answers1

3

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);
Botje
  • 26,269
  • 3
  • 31
  • 41
  • Thanks @Botje, I updated my class in the question to what i think you were suggesting. But now I'm getting the error "use of undeclared identifier "QNetworkManager" – SilverSerpent03 Oct 11 '21 at 12:21
  • I'm sorry these are probably obvious things one should know but I've been trying to teach myself c++ and only started 2 days ago – SilverSerpent03 Oct 11 '21 at 12:22
  • 1
    That was a typo, should have been QNetworkAccessManager – Botje Oct 11 '21 at 12:22
  • Thanks for the help @Botje, this fixed the error but not the program, The class is still exiting without uploading to the database. Original question:https://stackoverflow.com/questions/69523389/app-closes-before-uploading-data-to-database-qt/69524722#69524722 – SilverSerpent03 Oct 11 '21 at 12:28
  • Also @Botje, I would highly recommend you put a donation link on your profile. You have commented on or answered nearly every post I've made on stack overflow and I'd be happy to donate to say thanks for all the amazing effort and help. – SilverSerpent03 Oct 11 '21 at 12:31
  • You should verify the status code with `x->attribute(QNetworkRequest::HttpStatusCodeAttribute)`. If not 200 inspect the body. I'm fairly confident you forgot to set your firebase API key in the request. – Botje Oct 11 '21 at 12:31
  • Thanks @Botje, where would i put that line though? – SilverSerpent03 Oct 11 '21 at 12:32
  • The only place where you have access to it, in `myOnFinishSlot`. Use `qDebug() << x->attribute(QNetworkRequest::HttpStatusCodeAttribute)` to print it, for example. – Botje Oct 11 '21 at 12:33
  • I implimented that, and still nothing happened. There was nothing in the application output of any new entry in the database – SilverSerpent03 Oct 11 '21 at 12:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/238021/discussion-between-botje-and-silverserpent03). – Botje Oct 11 '21 at 12:36