0

I started working on the GUI for an application in C++ using the Qt-Creator and Designer. I always added the new files (cpp, h, ui) by using the dialog that Qt provides.

Here's what I get now:

moc_basewidget.obj:-1: Error: LNK2019: unresolved external signal ""public: void __cdecl BaseWidget::onNewProjects(void)" (?onNewProjects@BaseWidget@@QEAAXXZ)" in function ""private: static void __cdecl BaseWidget::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@BaseWidget@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)".

Here's my BaseWidget.h:

#ifndef BASEWIDGET_H    
#define BASEWIDGET_H

#include <QWidget>
#include "mainmenu.h"
#include "projectlist.h"

namespace Ui {
class BaseWidget;
}

class BaseWidget : public QWidget
{
    Q_OBJECT

public:
    explicit BaseWidget(QWidget *parent = 0);
    ~BaseWidget();

public slots:
  //called in MainMenu
  void onProjects();    

private:
    Ui::BaseWidget *ui;
    MainMenu * mainMenu;
    ProjectList * projectList;
};

#endif //BASEWIDGET_H

And my BaseWidget.cpp:

#include "basewidget.h"
#include "ui_basewidget.h"

BaseWidget::BaseWidget(QWidget *parent) : QWidget(parent), ui(new Ui::BaseWidget) {

    ui->setupUi(this);

    //add all the widgets

    this->mainMenu = new MainMenu(this);
    ui->stackedWidget->addWidget(mainMenu);
    this->projectList = new ProjectList(this);
    ui->stackedWidget->addWidget(projectList);

}

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

void BaseWidget::onProjects()
{
    ui->stackedWidget->setCurrentWidget(this->projectList);
}

And finally, my .pro file:

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = GUI
TEMPLATE = app


SOURCES += main.cpp\
        basewidget.cpp \
    mainmenu.cpp \
    projectlist.cpp

HEADERS  += basewidget.h \
    mainmenu.h \
    projectlist.h

FORMS    += basewidget.ui \
    mainmenu.ui \
    projectlist.ui

I've read about it for hours now. I tried cleaning the build-directory and rebuilding, but it always comes down to this.

Saftkeks
  • 181
  • 2
  • 15
  • 1
    Did you have in this class `onNewProjects()` and then delete it? I can't see it in your code. – Shtol Krakov Jun 01 '16 at 12:36
  • 1
    My guess is that `onNewProjects()` was once a slot in your `BaseWidget` class and moc has not regenerated the moc source for this class. Take a look at the generated moc_basewidget* file. – drescherjm Jun 01 '16 at 12:42
  • 1
    @drescherjm as variant. Anyway, @Saftkeks, are you always using designer for ui? Take a look for items in it and their slots/signals - maybe in one of them you use deleted `onNewProjects()` somewhere? – Shtol Krakov Jun 01 '16 at 12:45
  • @someoneinthebox : indeed, I was missing the method in the cpp file. Oh boy. Can't remember the last time I felt so dumb. Thanks for your time. – Saftkeks Jun 01 '16 at 13:11

0 Answers0