Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Link error when showing a new form



  • 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


  • Lifetime Qt Champion

    @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?



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



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



  • @jsulm @Gerhard @Pl45m4

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


Log in to reply