Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Link error when showing a new form
Forum Update on Monday, May 27th 2025

Link error when showing a new form

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 313 Views
  • 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.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by viniltc
    #1

    Hi all,

    I'm getting a strange Link error on showing a form

    #include "stagetwopatients.h"
    #include "ui_stagetwopatients.h"
    #include "stageonemain.h"
    #include "stagetwonew.h"
    
    
    StageTwoPatients::StageTwoPatients(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::StageTwoPatients)
    {
        ui->setupUi(this);
    
    
        this->setStyleSheet("background-color: white;");
        this->setFixedSize(this->width(),this->height());
    }
    
    StageTwoPatients::~StageTwoPatients()
    {
        delete ui;
    }
    
    void StageTwoPatients::on_pushButton_bmain_clicked()
    {
       hide();
       StageOneMain *back =new StageOneMain(this);
       back ->show();
    }
    
    void StageTwoPatients::on_pushButton_new_clicked()
    {
    
        hide();
        StageTwoNew *newone = new StageTwoNew(this);
        newone->show();
    
    }
    
    

    the Link error is as follows :

    stagetwopatients.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl StageTwoNew::StageTwoNew(class QWidget *)" (??0StageTwoNew@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl StageTwoPatients::on_pushButton_new_clicked(void)" (?on_pushButton_new_clicked@StageTwoPatients@@AEAAXXZ)
    
    

    Any idea, Where am I done wrong?

    Thank you

    jsulmJ Pl45m4P 2 Replies Last reply
    0
    • V viniltc

      Hi all,

      I'm getting a strange Link error on showing a form

      #include "stagetwopatients.h"
      #include "ui_stagetwopatients.h"
      #include "stageonemain.h"
      #include "stagetwonew.h"
      
      
      StageTwoPatients::StageTwoPatients(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::StageTwoPatients)
      {
          ui->setupUi(this);
      
      
          this->setStyleSheet("background-color: white;");
          this->setFixedSize(this->width(),this->height());
      }
      
      StageTwoPatients::~StageTwoPatients()
      {
          delete ui;
      }
      
      void StageTwoPatients::on_pushButton_bmain_clicked()
      {
         hide();
         StageOneMain *back =new StageOneMain(this);
         back ->show();
      }
      
      void StageTwoPatients::on_pushButton_new_clicked()
      {
      
          hide();
          StageTwoNew *newone = new StageTwoNew(this);
          newone->show();
      
      }
      
      

      the Link error is as follows :

      stagetwopatients.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl StageTwoNew::StageTwoNew(class QWidget *)" (??0StageTwoNew@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl StageTwoPatients::on_pushButton_new_clicked(void)" (?on_pushButton_new_clicked@StageTwoPatients@@AEAAXXZ)
      
      

      Any idea, Where am I done wrong?

      Thank you

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @viniltc said in Link error when showing a new form:

      StageTwoNew::StageTwoNew

      The error message tells you that StageTwoNew constructor is not defined.
      You include

      #include "stagetwonew.h"
      

      did you also add stagetwonew.cpp to your project?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • GerhardG Offline
        GerhardG Offline
        Gerhard
        wrote on last edited by
        #3

        Is "stagetwonew.cpp" included in the Project ?
        is qmake run after added class StageTwoNew ?

        Gerhard

        1 Reply Last reply
        2
        • V viniltc

          Hi all,

          I'm getting a strange Link error on showing a form

          #include "stagetwopatients.h"
          #include "ui_stagetwopatients.h"
          #include "stageonemain.h"
          #include "stagetwonew.h"
          
          
          StageTwoPatients::StageTwoPatients(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::StageTwoPatients)
          {
              ui->setupUi(this);
          
          
              this->setStyleSheet("background-color: white;");
              this->setFixedSize(this->width(),this->height());
          }
          
          StageTwoPatients::~StageTwoPatients()
          {
              delete ui;
          }
          
          void StageTwoPatients::on_pushButton_bmain_clicked()
          {
             hide();
             StageOneMain *back =new StageOneMain(this);
             back ->show();
          }
          
          void StageTwoPatients::on_pushButton_new_clicked()
          {
          
              hide();
              StageTwoNew *newone = new StageTwoNew(this);
              newone->show();
          
          }
          
          

          the Link error is as follows :

          stagetwopatients.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl StageTwoNew::StageTwoNew(class QWidget *)" (??0StageTwoNew@@QEAA@PEAVQWidget@@@Z) referenced in function "private: void __cdecl StageTwoPatients::on_pushButton_new_clicked(void)" (?on_pushButton_new_clicked@StageTwoPatients@@AEAAXXZ)
          
          

          Any idea, Where am I done wrong?

          Thank you

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @viniltc said in Link error when showing a new form:

          StageTwoPatients::StageTwoPatients(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::StageTwoPatients)

          This is technically not wrong, but I would avoid using multiple QMainWindows.
          Especially when they are hiding / showing each other.
          (I assume StageOneMain, StageTwoNew are QMainWindow- derived classes as well?!)

          Better use QDialogs or QWidgets with only one (parent) QMainWindow.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          2
          • V Offline
            V Offline
            viniltc
            wrote on last edited by
            #5

            @jsulm @Gerhard @Pl45m4

            Thanks a lot guys for the suggestions. The error was because I forgot to do qmake!

            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