3
votes

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
4
My guess is that the designer should also generate a dodajprodukt.cpp file with the window's implementation that you're not linking with your project.Kos
@kos how to link it into my project?Norbert Pisz

4 Answers

1
votes

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.

3
votes

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

1
votes

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
0
votes

I have the same problem.

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