LNK2019 error when including a basic form.
-
Hi guys,
Well I've been trying now for about an hour right now to figure out why I'm getting this issue. To give details, currently all I'm doing is literally including a new QT Designer Form Class into my project. Now when I go to create a new instance of that form in my MainWindow, I keep getting the following error:
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall aboutForm::aboutForm(class QWidget *)" (??0aboutForm@@QAE@PAVQWidget@@@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)My New Empty Form, Titled "aboutForm"
@
#ifndef ABOUTFORM_H
#define ABOUTFORM_H#include <QWidget>
namespace Ui {
class aboutForm;
}class aboutForm : public QWidget
{
Q_OBJECTpublic:
explicit aboutForm(QWidget *parent = 0);
~aboutForm();private:
Ui::aboutForm *ui;
};#endif // ABOUTFORM_H
@MainWindow.h
@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QApplication>
#include <QDesktopWidget>
#include <QPainter>
#include <QDebug>
#include <QFile>
#include <QHash>
#include <QDataStream>
#include <QMessageBox>
#include "aboutForm.h"namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();public slots:
void aboutQT();
void actionAbout();private:
Ui::MainWindow *ui;
aboutForm *about;
};#endif // MAINWINDOW_H
@MainWindow.cpp:
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);//Abouts connect(ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQT())); about = new aboutForm();
}
MainWindow::~MainWindow()
{
delete ui;
}//Action Function Slots
void MainWindow::aboutQT()
{
QMessageBox::aboutQt(this);
}void MainWindow::actionAbout()
{
}
@And finally my Pro File:
@
QT += core guiTARGET = BDEditor
TEMPLATE = appCONFIG += console
SOURCES += main.cpp
mainwindow.cpp
map.cpp
enemies.cpp
tilelayer.cpp
aboutform.cppHEADERS += mainwindow.h
map.h
enemies.h
tilelayer.h
aboutform.hFORMS += mainwindow.ui
aboutform.uiRESOURCES +=
Images.qrc
@Everything seems to be linked into .pro file correctly so I'm slightly confused on where the error could be. Just for note, i am currently just trying to get to grips with QT 5 Rc2 so any help would be greatly appreciated! :)
-
Try:
@
about = new Ui::aboutForm();
@instead (in constructor). You don't really need namespacing, by the way (I know it's default in QtC).
-
Well, no more linker error, but now i get;
@
C:\Users\Daniel\Projects\BDEditor\BDEditor\mainwindow.cpp:11: error: C2512: 'Ui::aboutForm' : no appropriate default constructor available
@ -
Strange. I'm almost sure it has something to do with that namespace in your about widget.
Try:
@
about = new Ui::aboutForm(this);
@
or:
@
about = new Ui::aboutForm; // no brackets
@ -
So With your first suggestion;
@
C:\Users\Daniel\Projects\BDEditor\BDEditor\mainwindow.cpp:11: error: C2514: 'Ui::aboutForm' : class has no constructors
@Seconded Suggestion, same as the first error. "No default constructor found"
-
Enclose the whole class in the namespace, or remove the namespace in aboutForm. Both will require some refactorin, but I think it will help.
-
[quote author="sierdzio" date="1355769644"]Enclose the whole class in the namespace, or remove the namespace in aboutForm. Both will require some refactorin, but I think it will help.[/quote]
And now i'm back to the Linker error :/. I deleted the namespace in aboutForm to leave me with;@
#ifndef ABOUTFORM_H
#define ABOUTFORM_H#include <QtWidgets/QWidget>
class aboutForm : public QWidget
{
Q_OBJECTpublic:
explicit aboutForm(QWidget *parent = 0);
~aboutForm();private:
aboutForm *ui;
};#endif // ABOUTFORM_H
@& the.cpp file now;
@
#include "aboutform.h"
#include "ui_aboutform.h"aboutForm::aboutForm(QWidget *parent) :
QWidget(parent),
ui(new aboutForm)
{
ui->setupUi(this);
}aboutForm::~aboutForm()
{
delete ui;
}
@Giving that same LNK2019 error message;
@
mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall aboutForm::aboutForm(class QWidget *)" (??0aboutForm@@QAE@PAVQWidget@@@Z) referenced in function "public: __thiscall MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QAE@PAVQWidget@@@Z)
@ -
So. I have it working now. But i have a weird explanation of how i got it to work.
See essentially what i've been doing is trying to convert over an old project from QT 4.8.Something, and i've been using the "Add Exisiting Files.." option.
I was trying to add in my old about form, that gave me the same linker error as above. Then i deleted it and thought i'd try making it a new file inside the project and copy in the code. But still that gave me errors. (Basically what's above is that attempt).So literally how i've fixed this is by making a new project, making all the necessary blank forms/classes in the same filename as my older ones and then updating the code in those files.. :S
Now i have no clue why things mess up if i try to include existing forms/files..