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. [Solved]Problem with incomplete type and forward declaration trying to add new file to project.
QtWS25 Last Chance

[Solved]Problem with incomplete type and forward declaration trying to add new file to project.

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 9.7k Views
  • 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.
  • S Offline
    S Offline
    SetBetterPass
    wrote on last edited by
    #1

    I am trying to add new file to my project, small find dialog but I have a problem I can't solve. Everything seems OK to me as I compare my header file for find dialog and for main window but anyway I am getting 4 errors
    2 times invalid use of incomplete type and 2 times forward declaration. Code is here:
    find.h
    @
    #ifndef FIND_H
    #define FIND_H

    #include <QWidget>
    #include "ui_find.h"

    namespace Ui {
    class FindDialog; //here is forward declaration, reported twice
    }

    class FindDialog : public QWidget{
    Q_OBJECT

    public:
    explicit FindDialog(QWidget *parent =0);
    ~FindDialog();

    private :
    Ui::FindDialog* ui;

    public slots:

    };
    #endif // FIND_H

    @
    find.cpp
    @
    #include "find.h"

    FindDialog::FindDialog(QWidget* parent) :
    QWidget(parent),
    ui(new Ui::FindDialog) //here is invalid use of incomplete type Ui::FindDialog
    {
    ui->setupUi(this); //and so here

    }
    FindDialog::~FindDialog(){
    delete ui;
    }
    @
    the same way I have it made in mainwindow but class name is MainWindow and it's public class of QMainWindow, not QWidget and it's working without any problems.
    Can someone help me please?
    Thanks. :)

    1 Reply Last reply
    0
    • ZlatomirZ Offline
      ZlatomirZ Offline
      Zlatomir
      wrote on last edited by
      #2

      At a first look it seems ok, did you run qmake after you added the class?

      LE: Also look into the file ui_find.h and see the name of the ui class that is in the Ui:: namespace //isn't it simple Find instead of FindDialog, you should have something like:
      @
      namespace Ui {
      class FindDialog: public Ui_FindDialog {};
      }
      @

      https://forum.qt.io/category/41/romanian

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MuldeR
        wrote on last edited by
        #3

        You have a forward declaration of "Ui::FindDialog" in your header file, yes.

        But where is the actual declaration?

        Of course you cannot create an instance of a class for which you have only a forward declaration!

        In your .cpp file, you normally include the header file created by the "UIC":http://qt-project.org/doc/qt-4.8/uic.html...

        --

        [EDIT]

        Okay, I just noticed that you include "ui_find.h" in your header file. I guess that is the UIC-generated header file.

        If you do it like that, then you do not need a forward declaration at all!

        But it's better to have a forward declaration, so you can move the include for the UIC header file to the .cpp file.

        Also double check what class the UIC header file actually defines. I apparently is not Ui::FindDialog...

        My OpenSource software at: http://muldersoft.com/

        Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

        Go visit the coop: http://youtu.be/Jay...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SetBetterPass
          wrote on last edited by
          #4

          Thanks Zlatomir I looked into ui_find.h file and found the class name is Ui_Form, added it there and it works now.

          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