Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt creator fails to create header files for UI's (Dialogs)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved General and Desktop
ui headerlink errorsqtcreatorwindows 10msvc2015
10 Posts 5 Posters 9.7k Views 5 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rhonaldjr
    wrote on last edited by
    #1

    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)

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

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

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      R 1 Reply Last reply
      4
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

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

        So does the destructor have default == NULL ?

        R 1 Reply Last reply
        1
        • dheerendraD dheerendra

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

          R Offline
          R Offline
          rhonaldjr
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          0
          • EddyE Offline
            EddyE Offline
            Eddy
            wrote on last edited by
            #5

            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

            Qt Certified Specialist
            www.edalsolutions.be

            R 1 Reply Last reply
            5
            • mrjjM mrjj

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

              So does the destructor have default == NULL ?

              R Offline
              R Offline
              rhonaldjr
              wrote on last edited by
              #6

              @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;
              }
              
              1 Reply Last reply
              0
              • EddyE Eddy

                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

                R Offline
                R Offline
                rhonaldjr
                wrote on last edited by
                #7

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

                1 Reply Last reply
                2
                • EddyE Offline
                  EddyE Offline
                  Eddy
                  wrote on last edited by
                  #8

                  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.

                  Qt Certified Specialist
                  www.edalsolutions.be

                  R 1 Reply Last reply
                  1
                  • EddyE Eddy

                    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.

                    R Offline
                    R Offline
                    rhonaldjr
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    1
                    • Pradeep KumarP Offline
                      Pradeep KumarP Offline
                      Pradeep Kumar
                      wrote on last edited by
                      #10

                      @rhonaldjr

                      u have marked as solved.
                      cheers.

                      Thanks,

                      Pradeep Kumar
                      Qt,QML Developer

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved