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 \
        dlglogin.cpp
    
    HEADERS  += mainwindow.h \
        dlglogin.h
    
    FORMS    += mainwindow.ui \
        dlglogin.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) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        DlgLogin login;
        login.setModal(true);
        login.show();
    
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        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)



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


  • Qt Champions 2016

    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


  • Moderators

    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.

    Eddy



  • @mrjj my dlglogin.h source code

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

    my dlglogin.cpp source code

    #include "dlglogin.h"
    #include "ui_dlglogin.h"
    
    DlgLogin::DlgLogin(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::DlgLogin)
    {
        ui->setupUi(this);
    }
    
    DlgLogin::~DlgLogin()
    {
        delete ui;
    }
    


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


  • Moderators

    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.
    cheers.

    Thanks,



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.