Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. QT Creator - LNK2019 error when editing the MainWindow.cpp constructor code
Forum Updated to NodeBB v4.3 + New Features

QT Creator - LNK2019 error when editing the MainWindow.cpp constructor code

Scheduled Pinned Locked Moved Qt Creator and other tools
6 Posts 2 Posters 7.4k 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.
  • P Offline
    P Offline
    Psycho_Path
    wrote on last edited by
    #1

    Added an InitMain function to a brand new QT Widget -> QT Gui Application so that my code calls the InitMain in the MainWindow's constructor. When compiling I get this error:

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

    Any help on resolving this issue would be much appreciated

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Welcome to devnet

      Do you have InitMain in the same source file as MainWindow?

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Psycho_Path
        wrote on last edited by
        #3

        Yes. Here's the .h and .cpp files for MainWindow (everything's default per the project creator other than the InitMain() function stuff)

        @
        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H

        #include <QMainWindow>

        namespace Ui {
        class MainWindow;
        }

        class MainWindow : public QMainWindow
        {
        Q_OBJECT

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

        private:
        Ui::MainWindow *ui;
        };

        #endif // MAINWINDOW_H
        @

        @
        #include "mainwindow.h"
        #include "ui_mainwindow.h"

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

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

        void InitMain()
        {
        int i = 5;
        i++;
        }
        @

        (I do realize that at this time InitMain is a pointless function)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          Please tag your code with '@' as explained "here ":http://developer.qt.nokia.com/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            You have implemented an independent function called InitMain(). You may do this, but you have declared a member function of MainWindow calls.

            You should write:
            @
            void MainWindows :: InitMain()
            {
            int i = 5;
            i++;
            }
            @

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Psycho_Path
              wrote on last edited by
              #6

              My appologies on not using the 'at' symbol. Thanks also for the solution. Checking it now. I'm not yet used to using the class definition before methods/functions

              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