Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. invalid use of incomplete type / forward decalration of 'class UI::file_ui'
Qt 6.12 LTS is out! See what's new in the release blog

invalid use of incomplete type / forward decalration of 'class UI::file_ui'

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 1.6k Views 1 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.
  • A Offline
    A Offline
    Adham
    wrote on last edited by Adham
    #1

    I have two files:

    module.h

    #ifndef MODULE_H
    #define MODULE_H
    
    #include "parent_module.h"
    
    class parent_module;
    
    class module : public parent_module
    {
    public:
        module();
    
        ...
    
    private:
    
        ...
    };
    
    #endif // MODULE_H
    

    and module_ui.h

    #ifndef MODULE_UI_H
    #define MODULE_UI_H
    
    #include ...
    
    #include "../module.h"
    
    namespace Ui {
    class module_ui;
    }
    
    class module;
    
    class module_ui : public QDialog, module
    {
        Q_OBJECT
    
    public:
       
       ...
    
    private:
    
       ...
    };
    
    #endif // MODULE_UI_H
    
    

    And this is the implementation for the ui header file: module_ui.cpp

    #include "module_ui.h"
    #include "ui_module_ui.h"
    
    module_ui::module_ui(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::module_ui) //error occurs here
    {
        ui->setupUi(this); //and here
        ...
    }
    
    module_ui::~module_ui()
    {
        qDebug() << "Module_UI destructor called";
        ...
        delete ui;  //and here (and basically everywhere ui is called)
    }
    

    Basically a parent/base class that is inheritted by child ui class. I have this same structure for many other files and it works fine. However when I added this set I keep getting the following errors:

    ..module_ui.cpp:28:16: error: invalid use of incomplete type 'class Ui::module_ui'
    ui(new Ui::module_ui)
    ^~~~~~~~~~~~~~~~~~~

    In file included from ..\module_ui.cpp:22:0:
    ..\module_ui.h:23:7: note: forward declaration of 'class Ui::module_ui'
    class module_ui;
    ^~~~~~~~~~~~~~~~~~~

    I have the all the files properly add in the .pro file (.cpp to SOURCES, .h to HEADERS, and .ui to FORMS)
    I literally went back and followed the exact same structure as all the other files which are working fine. I've got no idea what I am missing here.

    Help is appreciated.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you check that uic is properly run on that form ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      A 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Did you check that uic is properly run on that form ?

        A Offline
        A Offline
        Adham
        wrote on last edited by
        #3

        @SGaist said in invalid use of incomplete type / forward decalration of 'class UI::file_ui':

        check

        I just checked and it is not.. The ui_module_ui.h file generated has instances of module.h instead of module_ui.h.

        class Ui_module //here it should be UI_module_ui
        {
        public:
            ...
            void setupUi(QDialog *module) //and here it should pass a pointer to module_ui
            {
             ... //all other instances are the same
            }
        

        I can fix it manually but that would not solve the problem for anyone building from scratch. Any idea why that is happening? I believe I have the include statements the right way round

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I currently wonder if you using _ui in your designer based widget does not trigger some issue.

          Try renaming it to something more meaningful without using _ui.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            I currently wonder if you using _ui in your designer based widget does not trigger some issue.

            Try renaming it to something more meaningful without using _ui.

            A Offline
            A Offline
            Adham
            wrote on last edited by Adham
            #5

            @SGaist renamed it and got the same issue. It shouldn't matter because I have like 20 other files named module_something_ui and they all work fine.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then with silly ideas: did you check whether you have a missing backslash in your .pro when listing that particular form ? If you do it one file per line that is.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              0
              • SGaistS SGaist

                Then with silly ideas: did you check whether you have a missing backslash in your .pro when listing that particular form ? If you do it one file per line that is.

                A Offline
                A Offline
                Adham
                wrote on last edited by
                #7

                @SGaist I'm pretty sure it'll be a silly one.
                Yep. One file per line, backslash after every file

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Did you already nuke the build folder and rebuild from scratch ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Adham
                    wrote on last edited by
                    #9

                    @SGaist I finally figured it out.

                    The module.h file was actually the ui file at first and then I created a child class module_ui.h that inherits from it and instantiates the actual QDialog. Soo, I changed everything up but forgot to change the class name in the .ui file.. Pretty silly

                    Anyways thanks for your help.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Adham said in invalid use of incomplete type / forward decalration of 'class UI::file_ui':

                      Pretty silly

                      So we were right ! :-D

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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
                      • Unsolved