Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File not found: mainwindow.obj

Tags:

c++

qt

  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:

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

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

private slots:
    void on_actionNew_triggered();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

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

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

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

void MainWindow::on_actionNew_triggered()
{
    EditStudentDialog editDialog;
    editDialog.setModal(true);
    editDialog.exec();
}

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

#ifndef EDITSTUDENTDIALOG_H
#define EDITSTUDENTDIALOG_H

#include <QDialog>

namespace Ui {
class EditStudentDialog;
}

class EditStudentDialog : public QDialog
{
    Q_OBJECT

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

private:
    Ui::EditStudentDialog *ui;
};

#endif // EDITSTUDENTDIALOG_H


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

EditStudentDialog::EditStudentDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::EditStudentDialog)
{
    ui->setupUi(this);
}

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

What am I doing wrong?

EDIT: This is the .pro file

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = GUI1
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    editstudentdialog.cpp

HEADERS  += mainwindow.h \
    editstudentdialog.h

FORMS    += mainwindow.ui \
    editstudentdialog.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

like image 584
Jack Willson Avatar asked Apr 07 '13 15:04

Jack Willson


1 Answers

Solution

  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.

like image 179
Pete McFarlane Avatar answered Oct 05 '22 13:10

Pete McFarlane