PDA

View Full Version : Modal Dialog unresolved external symbol



gpuckett
15th June 2014, 21:44
I am trying to design a modal dialog that will perform a search on a database and allow the user to select an item and then return it back to the calling program. This is my first attempt at producing a dialog and must be doing something very basic wrong. I have set up a simple project in Qt Creator. It has a main window with a single button. When I click on the button I want to bring up the dialog. For the moment I just want the dialog to come up and go away when I click cancel. When I try to build the project I am getting an unresolved external symbol. I have tried a little of everything. Being fairly new to Qt and C++ this just doesn't make sense to me.

I have the main window and the dialog set up in forms.

The main window has the following header:


#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();

public slots:
void doAddressSearch();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

Here is the main window code:


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "addressdialog.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->addressSearchButton, SIGNAL(clicked()), this, SLOT(doAddressSearch()));
}

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

void MainWindow::doAddressSearch()
{
AddressDialog *addrDialog = new AddressDialog(this);
addrDialog->show();
}


The dialog header has:


#ifndef ADDRESSDIALOG_H
#define ADDRESSDIALOG_H

#include <QDialog>

namespace Ui {
class AddressDialog;
}

class AddressDialog : public QDialog
{
Q_OBJECT

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

private:
Ui::AddressDialog *ui;
};

#endif // ADDRESSDIALOG_H

And here is the dialog code:


#include "addressdialog.h"
#include "ui_addressdialog.h"

AddressDialog::AddressDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AddressDialog)
{
ui->setupUi(this);
QDialog::connect(ui->cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
}

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


When I perform the build I get:


mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall AddressDialog::AddressDialog(class QWidget *)" (??0AddressDialog@@QAE@PAVQWidget@@@Z) referenced in function "public: void __thiscall MainWindow::doAddressSearch(void)" (?doAddressSearch@MainWindow@@QAEXXZ)

What am I doing wrong?

MarkoSan
15th June 2014, 21:50
Did you add Address dialog to .pro file?

gpuckett
16th June 2014, 15:41
Here is the pro file:


#-------------------------------------------------
#
# Project created by QtCreator 2014-06-15T14:15:32
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = ListView
TEMPLATE = app


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

HEADERS += mainwindow.h \
addressdialog.h

FORMS += mainwindow.ui \
addressdialog.ui


Added after 41 minutes:

This is really frustrating!!! I closed down Qt Creator, deleted the build directory and the pro.user file. Then I restarted Qt Creator and did a build. It compiled fine and the application ran without issue. I don't know what is the problem with Qt Creator but this should not be happening. I suppose all that matters at this point is that it is now working. I spent 6 hours yesterday struggling with this. Is there a valid reason why Qt Creator does this? I have experienced this before. It just didn't dawn on me this could be what I needed to do this time.