Qt World Summit: Register Today!

Qt creator fails to create header files for UI's (Dialogs)

  • Hi,

    In my Desktop Application, I have created a dialog UI through the IDE (derived from QDialog).

    DlgLogin, derived from QDialog

    I can find the UI, .cpp and .h added to the project file (below).

    SOURCES += main.cpp\
            mainwindow.cpp \
    HEADERS  += mainwindow.h \
    FORMS    += mainwindow.ui \

    When I compile, there is no issue. But when I refer the dialog file like the below, the program doesn't run.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QMessageBox>
    #include "dlglogin.h"
    MainWindow::MainWindow(QWidget *parent) :
        ui(new Ui::MainWindow)
        DlgLogin login;
        delete ui;

    it gives the below errors.

    *mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl DlgLogin::DlgLogin(class QWidget *)" (??0DlgLogin@@QEAA@PEAVQWidget@@@Z) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget *)" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
    mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: virtual __cdecl DlgLogin::~DlgLogin(void)" (??1DlgLogin@@UEAA@XZ) referenced in function "public: __cdecl MainWindow::MainWindow(class QWidget )" (??0MainWindow@@QEAA@PEAVQWidget@@@Z)
    debug\Akounts.exe:-1: error: LNK1120: 2 unresolved externals

    When I add include "ui_dlglogin.h" in the header, it gives the below error message.
    XXX\mainwindow.cpp:3: error: C1083:Cannot open include file: 'ui_dlglogin.h': No such file or directory

    My build directory is outside the project folder and I cannot find ui_dlglogin.h file inside. I can understand that the UI compiler is not able to generate the source code and hence the linker is throwing this error message. How do I resolve this? I have gone through the responses in most of the forums and it didn't work.

    I am currently working on Windows 10 machine with Qt Creator 4.2.1, MSVC 2015 32-Bit compiler (my machine is 64 bit and I am using 64 bit Qt)

  • Qt Champions 2017

    Can you check which directory the ui_dlglogin.h file exist ? Does it exist in some directory ?

  • Lifetime Qt Champion

    Can you show your constructor of the dialog
    It looks for
    DlgLogin::DlgLogin(class QWidget *)

    So does the destructor have default == NULL ?

  • @dheerendra I didn't find ui_dlglogin.h anywhere. The build directory is outside the project directory and I didn't find it there. However, I can find ui_mainwindow.h there

  • Hi,

    Sometimes if you make important changes to a project it is a good thing to uses 'Clean' + 'Qmake' + rebuild.
    This might help the linker finding what it needs.


  • @mrjj my dlglogin.h source code

    #ifndef DLGLOGIN_H
    #define DLGLOGIN_H
    #include <QDialog>
    namespace Ui {
    class DlgLogin;
    class DlgLogin : public QDialog
        explicit DlgLogin(QWidget *parent = 0);
        Ui::DlgLogin *ui;
    #endif // DLGLOGIN_H

    my dlglogin.cpp source code

    #include "dlglogin.h"
    #include "ui_dlglogin.h"
    DlgLogin::DlgLogin(QWidget *parent) :
        ui(new Ui::DlgLogin)
        delete ui;

  • @Eddy thanks. This one helped. after 4 hours, I saw my program run :-)

  • Glad you can move on!

    We all have been in the same situation like you had just now. ;-)
    Every time I see linker errors like this I clean my project as described.

    Could you please mark the topic as solved.

  • @Eddy thanks a lot. I thought I had marked as solved. Let me check

  • @rhonaldjr

    u have marked as solved.