Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. LNK2019 error when including a basic form.
Forum Updated to NodeBB v4.3 + New Features

LNK2019 error when including a basic form.

Scheduled Pinned Locked Moved C++ Gurus
8 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dan369
    wrote on last edited by
    #1

    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_OBJECT

    public:
    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_OBJECT

    public:
    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 gui

    TARGET = BDEditor
    TEMPLATE = app

    CONFIG += console

    SOURCES += main.cpp
    mainwindow.cpp
    map.cpp
    enemies.cpp
    tilelayer.cpp
    aboutform.cpp

    HEADERS += mainwindow.h
    map.h
    enemies.h
    tilelayer.h
    aboutform.h

    FORMS += mainwindow.ui
    aboutform.ui

    RESOURCES +=
    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! :)

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Try:
      @
      about = new Ui::aboutForm();
      @

      instead (in constructor). You don't really need namespacing, by the way (I know it's default in QtC).

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dan369
        wrote on last edited by
        #3

        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
        @

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          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
          @

          (Z(:^

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dan369
            wrote on last edited by
            #5

            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"

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              Enclose the whole class in the namespace, or remove the namespace in aboutForm. Both will require some refactorin, but I think it will help.

              (Z(:^

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dan369
                wrote on last edited by
                #7

                [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_OBJECT

                public:
                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)
                @

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dan369
                  wrote on last edited by
                  #8

                  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..

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved