File not found: mainwindow.obj

  1. I created a GUI Application -> QMainWindow
  2. I added 1 item to the menu + the slot.
  3. I created a new item -> QDialog
  4. I the slot method i try to show the created dialog but i get this errors:

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl EditStudentDialog::EditStudentDialog(class QWidget *)" (??0EditStudentDialog@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl MainWindow::on_actionNew_triggered(void)" (?on_actionNew_triggered@MainWindow@@AEAAXXZ)

    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __cdecl EditStudentDialog::~EditStudentDialog(void)" (??1EditStudentDialog@@UEAA@XZ) referenced in function "private: void __cdecl MainWindow::on_actionNew_triggered(void)" (?on_actionNew_triggered@MainWindow@@AEAAXXZ)

This is the main window:


#include <QMainWindow>

namespace Ui {
class MainWindow;

class MainWindow : public QMainWindow

    explicit MainWindow(QWidget *parent = 0);

private slots:
    void on_actionNew_triggered();

    Ui::MainWindow *ui;

#endif // MAINWINDOW_H

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "editstudentdialog.h"

MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    delete ui;

void MainWindow::on_actionNew_triggered()
    EditStudentDialog editDialog;

This is the dialog ( just an empty one, no controls on it ):


#include <QDialog>

namespace Ui {
class EditStudentDialog;

class EditStudentDialog : public QDialog

    explicit EditStudentDialog(QWidget *parent = 0);

    Ui::EditStudentDialog *ui;


#include "editstudentdialog.h"
#include "ui_editstudentdialog.h"

EditStudentDialog::EditStudentDialog(QWidget *parent) :
    ui(new Ui::EditStudentDialog)

    delete ui;

What am I doing wrong?

EDIT: This is the .pro file

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets


SOURCES += main.cpp\
        mainwindow.cpp \

HEADERS  += mainwindow.h \

FORMS    += mainwindow.ui \

PS: I tried to clean the project and then build it but still the same issue.

EDIT 2: I am using Qt Creator 2.7 with Qt 5.0.2


It seems that editstudentdialog.obj file is not created properly. Try to clean the project (Build->Clean all) and the build it again. If it does not help check if editstudentdialog.cpp is added to the SOURCES variable in your .pro file. If still nothing happens please provide the .pro file.

EDIT: As was mentioned below, you may also try to delete the whole app and create it again.

  1. Right click on project > Clean

  2. Right click on project > Run qmake

  3. Right click on project > Build

  4. Run - worked first time

Why it works

The reason this worked is because Run qmake updates your Makefile. For some reason qt is not automatically updating paths when you make changes to your project such as adding or removing files. Running qmake forces qt to update the paths for your project which enables it to find the mainwindow.obj file. You probably could just run qmake and your problem would be solved.

I just experienced the same issue. "Build All", "Rebuild All", "Clean All" did not help me to solve the "unresolved external symbol" problem.

However, after I have completely deleted the build directory (in my case C:\dev\projects\qt\build-qt-gui-test-Desktop_Qt_5_0_2_MSVC2010_32bit-Debug) the rebuild worked as a charm.

Hope this help you, vladimir

I just wanted to add this answer for anyone else (mainly noobs) who had to create an entirely new project to resolve the issue:

I had an extra slot definition in my headers file which prevented the entire application from running, and gave me errors pointing to a function which was not the problem. FYI.

Another reason why this may occur is because the .pro file references something that is nonexistent. It happened to me and once I removed those references, the errors were gone.

another reason this happens is if your function it's referencing is declared as an inline function in the header

In my case the fix was to add a Q_OBJECT macro in the beginning of the QObject-deriving class that was mentioned in the error messages. I don't know why I didn't get messages that more specifically pointed me to the missing macro.

Need Your Help

JavaScript XMLHttpRequest using JsonP

javascript ajax jsonp

I want to send request parameters to other domain

How to access a variable from another script in another gameobject through GetComponent?

c# reference unity3d

I've searched around and I just can't get this to work. I think I just don't know the proper syntax, or just doesn't quite grasp the context.