c++qtexternals

Qt LNK1120 Unresolved External


I'm trying to make the following code work, but no idea why im getting this error.

Im having a mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "user.h"
#include <QObject>
#include <QEvent>

#include "logindialog.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:

    void on_actionTest_triggered();

    void on_actionExit_triggered();

private:
    Ui::MainWindow *ui;
    User *_User;

    void doLogin(void);
    User getUser(QString);
};

#endif // MAINWINDOW_H

and a windwindow.cpp

#include "mainwindow.h"
#include "ui_RMS_MainWindow.h"
#include "logindialog.h"
#include <QtCore>
#include <QtGui>
#include <QDebug>
#include <QApplication>

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

MainWindow::~MainWindow()
{
    delete ui;
}

void doLogin()
{
    //LoginDialog aLoginDialog;
    //aLoginDialog.setModal(true);
    //aLoginDialog.exec();

    qDebug() << "user log in needed";
}

void MainWindow::on_actionTest_triggered()
{
    if(_User == NULL)
    {
        qDebug() << "user log in needed";
        MainWindow::doLogin();
    }
    else
    {
        qDebug() << "sepp";
    }
}

void MainWindow::on_actionExit_triggered()
{
    QCoreApplication::quit();
}

When i try to run the code to open the dialog in the button triggered action it runs, when i try to call MainWindow::doLogin i get the "unresolved externals" error.


Solution

  • Hm. You have doLogin() function defined but it's not a MainWindow class method. You need to define it as

    void MainWindow::doLogin()