0

I'm new using Qt c++, I am trying to make a unit test for a GUI, but I can't make a correct instance of my mainwindow class; when I try to build my project I have the following error: Error: undefined reference to MainWindow::MainWindow(QWidget*)'`

I hope you can help me or guide me!!

mainwindow.cpp

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

#include <QString>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    setMinimumHeight(MIN_H);
    setMinimumWidth(MIN_W);
    ui->setupUi(this);
}

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

void MainWindow::on_pushButton_clicked()
{
    val = QString::number(minimumHeight());
    ui->m_Height->setText(val);
    ui->m_Width->setText(QString::number(minimumWidth()));

    secInstance = new secDialog(this);
    secInstance->show();
}

int MainWindow::give_data(){
    int data = 1;

    return data;
}

tst_gui_test.h

#ifndef TST_GUI_TEST_H
#define TST_GUI_TEST_H

#include <QTest>
#include "mainwindow.h"

class GUI_TEST : public QObject
{
    Q_OBJECT

private slots:
    void TestSize();

};

#endif // TST_GUI_TEST_H

tst_gui_test.cpp

#include "tst_gui_test.h"


void GUI_TEST::TestSize(){
    //MainWindow instance
    MainWindow obj;
    QVERIFY2(2 == MainWindow::MIN_H, "Not setted");
}

QTEST_MAIN(GUI_TEST)
  • 2
    How are you building (compiling and linking) your programs? – MikeCAT Jul 20 '22 at 19:19
  • Hello @MikeCAT, i'm using the QT creator. And in my .pro file (of the unit test) I wrote the following: `INCLUDEPATH += \ ../mainTestWindow LIBS += \ -L../mainTestWindow` – Alberto Caraveo Jul 20 '22 at 19:58

0 Answers0