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;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
public slots:
void doAddressSearch();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#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
To copy to clipboard, switch view to plain text mode
Here is the main window code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "addressdialog.h"
MainWindow
::MainWindow(QWidget *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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
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
#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
To copy to clipboard, switch view to plain text mode
And here is the dialog code:
#include "addressdialog.h"
#include "ui_addressdialog.h"
AddressDialog
::AddressDialog(QWidget *parent
) : ui(new Ui::AddressDialog)
{
ui->setupUi(this);
QDialog::connect(ui
->cancelButton,
SIGNAL(clicked
()),
this,
SLOT(reject
()));
}
AddressDialog::~AddressDialog()
{
delete ui;
}
#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;
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks