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. Invalid use of incomplete type (but I include the header file (?))
Forum Updated to NodeBB v4.3 + New Features

Invalid use of incomplete type (but I include the header file (?))

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 5 Posters 1.8k 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.
  • F Offline
    F Offline
    fT3g0
    wrote on 7 Nov 2019, 08:47 last edited by
    #1

    Hi! The problematic pieces of code seem to be this:

    ui_createnode.h:

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

    ui_createnode.cpp:

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

    The error I get is:
    invalid use of incomplete type 'class Ui::Ui_createNode'
    ui(new Ui::Ui_createNode)
    ^~~~~~~~~~~~~

    But I did include the header file so what's wrong?
    Kind regards

    J 1 Reply Last reply 7 Nov 2019, 08:48
    0
    • F fT3g0
      7 Nov 2019, 08:47

      Hi! The problematic pieces of code seem to be this:

      ui_createnode.h:

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

      ui_createnode.cpp:

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

      The error I get is:
      invalid use of incomplete type 'class Ui::Ui_createNode'
      ui(new Ui::Ui_createNode)
      ^~~~~~~~~~~~~

      But I did include the header file so what's wrong?
      Kind regards

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 7 Nov 2019, 08:48 last edited by jsulm 11 Jul 2019, 08:53
      #2

      @fT3g0 Do a complete rebuild: delete build folder, run qmake and build.
      One moment: why do you have Ui::Ui_createNode *ui inside Ui::Ui_createNode?!
      ui classes are used in "normal" classes. So, you should have a class called createNode where you put Ui::Ui_createNode *ui;

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • F Offline
        F Offline
        fT3g0
        wrote on 7 Nov 2019, 22:25 last edited by fT3g0 11 Jul 2019, 22:27
        #3

        The entire project is somewhat bigger.

        What I want to do is to show a dialog when executing a function which is member of a different class, with custom UI.

        I created ui_createnode.h, /-.cpp, /-.ui by adding a designer form class.

        in net.cpp (not the entire file):

        void Net::createNode()
        {   
        QDialog *dialog_createNode = new QDialog;
        
            Ui_createNode *ui_createNode;
            dialog_createNode->setupUi(ui_createNode);
        // ERROR: no member named setupUi in QDialog; how do I add the UI to the dialog?
        
            dialog_createNode->show();
        // more stuff here
        }
        
        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 8 Nov 2019, 05:57 last edited by
          #4

          @fT3g0 said in Invalid use of incomplete type (but I include the header file (?)):

          how do I add the UI to the dialog?

          The way you do it in your first post. QDialog doesn't have a member setupUi() but the generated Ui class has.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          3
          • F Offline
            F Offline
            fT3g0
            wrote on 8 Nov 2019, 09:53 last edited by
            #5

            I still haven't managed to solve the problem (sorry for being a noob xD)....

            I tried to create the designer form class from scratch and named it "createNodeForm" so I don't have an "ui_" in front which could be confusing.

            createnodeform.h

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

            createnodeform.cpp

            #include "createnodeform.h"
            #include "ui_createnodeform.h"
            
            createNodeForm::createNodeForm(QWidget *parent) :
                QDialog(parent),
                ui(new Ui::createNodeForm)            //ERROR: invalid use of incomplete type class "Ui::createNodeForm"
            {
                ui->setupUi(this);
            }
            
            createNodeForm::~createNodeForm()
            {
                delete ui;
            }
            
            

            net.cpp

            #include "net.h"
            #include "mainwindow.h"
            #include "createnodeform.h"
            #include "ui_createnodeform.h"
            
            // other includes
            
            // other functions
            
            void Net::createNode()
            {
            
            
                QDialog *dialog_createNode = new QDialog;
            
                createNodeForm *ui_createNode = new createNodeForm;
                 //need to setup the UI and connect it to the dialog, what to do here?
            
            
                dialog_createNode->show();
            
                //other stuff inside the function
            
            }
            

            So there is the "incomplete type" error and I haven't managed to connect the UI to the dialog yet.

            Also I'm confused what ui_createnodeform.h is about... Is it an automatically generated file (as opposed to createnodeform.h, which I can see and edit)? What is in it and why do I need it?

            Also this seems kind of convoluted, having 3 files for every little dialog with custom UI. Is there a simpler way or does one just keep it tidy by using directories at some point?

            Kind regards

            J P 2 Replies Last reply 8 Nov 2019, 10:59
            0
            • F fT3g0
              8 Nov 2019, 09:53

              I still haven't managed to solve the problem (sorry for being a noob xD)....

              I tried to create the designer form class from scratch and named it "createNodeForm" so I don't have an "ui_" in front which could be confusing.

              createnodeform.h

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

              createnodeform.cpp

              #include "createnodeform.h"
              #include "ui_createnodeform.h"
              
              createNodeForm::createNodeForm(QWidget *parent) :
                  QDialog(parent),
                  ui(new Ui::createNodeForm)            //ERROR: invalid use of incomplete type class "Ui::createNodeForm"
              {
                  ui->setupUi(this);
              }
              
              createNodeForm::~createNodeForm()
              {
                  delete ui;
              }
              
              

              net.cpp

              #include "net.h"
              #include "mainwindow.h"
              #include "createnodeform.h"
              #include "ui_createnodeform.h"
              
              // other includes
              
              // other functions
              
              void Net::createNode()
              {
              
              
                  QDialog *dialog_createNode = new QDialog;
              
                  createNodeForm *ui_createNode = new createNodeForm;
                   //need to setup the UI and connect it to the dialog, what to do here?
              
              
                  dialog_createNode->show();
              
                  //other stuff inside the function
              
              }
              

              So there is the "incomplete type" error and I haven't managed to connect the UI to the dialog yet.

              Also I'm confused what ui_createnodeform.h is about... Is it an automatically generated file (as opposed to createnodeform.h, which I can see and edit)? What is in it and why do I need it?

              Also this seems kind of convoluted, having 3 files for every little dialog with custom UI. Is there a simpler way or does one just keep it tidy by using directories at some point?

              Kind regards

              J Offline
              J Offline
              JonB
              wrote on 8 Nov 2019, 10:59 last edited by
              #6

              @fT3g0
              I'm afraid I know nothing about Qt Designer and its code. Hope I am not actually confusing you. But for:

              ui(new Ui::createNodeForm)            //ERROR: invalid use of incomplete type class "Ui::createNodeForm"
              

              In your header file you have:

              namespace Ui {
              class createNodeForm;
              }
              
              class createNodeForm : public QDialog
              {
                  ...
              

              The first bit declares that there is a class createNodeForm in namespace Ui, i.e. the Ui::createNodeForm. It does not define that class. The second bit defines a class createNodeForm, but that isn't in namespace Ui. I don't know, but is your createNodeForm supposed to be in inside the namespace Ui?

              And I don't know why you seem to want to create a generic QDialog separately from your createNodeForm, which is a QDialog itself. You're only supposed to create your form-dialog....

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 8 Nov 2019, 11:20 last edited by
                #7

                @fT3g0 said in Invalid use of incomplete type (but I include the header file (?)):

                ui_createnodeform.h

                Please take a look into this file and make sure there is only one version of it available. Also simply try to remove it to make sure it's the correct one - it is created again by uic.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                J 1 Reply Last reply 8 Nov 2019, 11:25
                1
                • C Christian Ehrlicher
                  8 Nov 2019, 11:20

                  @fT3g0 said in Invalid use of incomplete type (but I include the header file (?)):

                  ui_createnodeform.h

                  Please take a look into this file and make sure there is only one version of it available. Also simply try to remove it to make sure it's the correct one - it is created again by uic.

                  J Offline
                  J Offline
                  JonB
                  wrote on 8 Nov 2019, 11:25 last edited by
                  #8

                  @Christian-Ehrlicher
                  So is my guess about the namespace declaration in C++ wrong, and I should delete my post as it's incorrect/unhelpful?

                  1 Reply Last reply
                  0
                  • F fT3g0
                    8 Nov 2019, 09:53

                    I still haven't managed to solve the problem (sorry for being a noob xD)....

                    I tried to create the designer form class from scratch and named it "createNodeForm" so I don't have an "ui_" in front which could be confusing.

                    createnodeform.h

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

                    createnodeform.cpp

                    #include "createnodeform.h"
                    #include "ui_createnodeform.h"
                    
                    createNodeForm::createNodeForm(QWidget *parent) :
                        QDialog(parent),
                        ui(new Ui::createNodeForm)            //ERROR: invalid use of incomplete type class "Ui::createNodeForm"
                    {
                        ui->setupUi(this);
                    }
                    
                    createNodeForm::~createNodeForm()
                    {
                        delete ui;
                    }
                    
                    

                    net.cpp

                    #include "net.h"
                    #include "mainwindow.h"
                    #include "createnodeform.h"
                    #include "ui_createnodeform.h"
                    
                    // other includes
                    
                    // other functions
                    
                    void Net::createNode()
                    {
                    
                    
                        QDialog *dialog_createNode = new QDialog;
                    
                        createNodeForm *ui_createNode = new createNodeForm;
                         //need to setup the UI and connect it to the dialog, what to do here?
                    
                    
                        dialog_createNode->show();
                    
                        //other stuff inside the function
                    
                    }
                    

                    So there is the "incomplete type" error and I haven't managed to connect the UI to the dialog yet.

                    Also I'm confused what ui_createnodeform.h is about... Is it an automatically generated file (as opposed to createnodeform.h, which I can see and edit)? What is in it and why do I need it?

                    Also this seems kind of convoluted, having 3 files for every little dialog with custom UI. Is there a simpler way or does one just keep it tidy by using directories at some point?

                    Kind regards

                    P Offline
                    P Offline
                    Pablo J. Rogina
                    wrote on 8 Nov 2019, 13:19 last edited by
                    #9

                    @fT3g0 could it be possible that you start from scratch? :-)

                    I mean, it seems from the files and filenames you posted that you're kind of misusing the capabilities of Designer and uic tool.

                    If you create a simple project in Qt Creator, or a form class with Designer, you'll see that 3 files are created (let's say it's a dialog named MyClass):

                    1. myclass.ui
                    2. myclass.h
                    3. myclass.cpp

                    you see that there's no ui_myclass.h file (yet...)

                    The idea is that you edit the form graphically with Designer (adding other widgets, buttons, labels, etc. to the dialog) and then you provide your dialog class implementation with the .h/.cpp (mainly the .cpp file).

                    The ui_myclass.h file will be created at compile time by the uic tool and it'll serve as a bridge between the GUI you designed and any implementation code you may need to better suit your class.

                    See more about using Designer and .ui files here.

                    Upvote the answer(s) that helped you solve the issue
                    Use "Topic Tools" button to mark your post as Solved
                    Add screenshots via postimage.org
                    Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    3

                    6/9

                    8 Nov 2019, 10:59

                    • Login

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