Norbert Pisz
Norbert Pisz

Reputation: 3440

Qt open second window

I can't open a new window/dialog form mainwindow in qt project.

Open function:

    void MainWindow::on_btDodajProdukt_clicked()
{
    newDialog = new DodajProdukt(this);
    newDialog->show();

}

MainWindow includes:

#include "dodajprodukt.h"

MainWindow.h

    DodajProdukt *newDialog;

Class DodajProdukt is new Window added in desinger.

I get this error:

mainwindow.obj:-1: błąd:LNK2019: unresolved external symbol "public: __thiscall DodajProdukt::DodajProdukt(class QWidget *)" (??0DodajProdukt@@QAE@PAVQWidget@@@Z) referenced in function "private: void __thiscall MainWindow::on_btDodajProdukt_clicked(void)" (?on_btDodajProdukt_clicked@MainWindow@@AAEXXZ)

EDIT:

dodajprodukt.cpp

    #include "dodajprodukt.h"
#include "ui_dodajprodukt.h"


DodajProdukt::DodajProdukt(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DodajProdukt)
{
    ui->setupUi(this);
}

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

Pro File:

    QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Hurtownia
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp \
    dodajprodukt.cpp \
    listaproduktow.cpp

HEADERS  += mainwindow.h \
    dodajprodukt.h \
    listaproduktow.h

FORMS    += mainwindow.ui \
    dodajprodukt.ui \
    listaproduktow.ui

Upvotes: 3

Views: 5570

Answers (4)

csch
csch

Reputation: 1455

Right click on project and then: Clean, Run qmake and Rebuild fixed it for me

Upvotes: 3

Galbarad
Galbarad

Reputation: 453

I have the same problem.

and I fix it after deleting .pro.user file and deleting project build folder

Upvotes: 0

user1951235
user1951235

Reputation:

I had the same error. Create a new Project and copy the code. Then create a simple sample code to check if this method works.

Upvotes: 1

Frank Osterfeld
Frank Osterfeld

Reputation: 25165

You must add all files related to DodajProdukt to your .pro file (if using qmake):

For the .ui file created in designer:

FORMS += dodajprodukt.ui # assuming that's how it's called

And as you apparently have also .h/.cpp files for it:

HEADERS += dodajprodukt.h
SOURCES += dodajprodukt.cpp

Upvotes: 1

Related Questions