Results 1 to 4 of 4

Thread: Subclass from Qt Ui Form Class, invalid use of incomplete type

  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Subclass from Qt Ui Form Class, invalid use of incomplete type

    Hi,

    i have a base class like this.
    ui_calib_base.h
    Qt Code:
    1. namespace Ui {
    2. class ui_calib_base;
    3. }
    4.  
    5. class ui_calib_base : public QWidget
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. explicit ui_calib_base(QWidget *parent = 0);
    11. ~ui_calib_base();
    12.  
    13. protected:
    14. Ui::ui_calib_base *ui;
    15. }
    To copy to clipboard, switch view to plain text mode 
    ui_calib_base.cpp
    Qt Code:
    1. ui_calib_base::ui_calib_base(QWidget *parent) : QWidget(parent), ui(new Ui::ui_calib_base)
    2. {
    3. ui->setupUi(this);
    4. ui->tabWidget->setCurrentIndex(0);
    5. }
    To copy to clipboard, switch view to plain text mode 
    I have moved the ui pointer to protected.

    My derived class looks like this:

    calib_analog.h
    Qt Code:
    1. #include <QObject>
    2. #include <QWidget>
    3.  
    4. #include <ui/ui_calib_base.h>
    5.  
    6. class calib_analog : public ui_calib_base
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit calib_analog(QWidget *parent = 0);
    11.  
    12. signals:
    13.  
    14. public slots:
    15. };
    To copy to clipboard, switch view to plain text mode 

    calib_analog.cpp
    Qt Code:
    1. #include "calib_analog.h"
    2.  
    3. calib_analog::calib_analog(QWidget *parent) : ui_calib_base(parent)
    4. {
    5. ui->tabWidget->setCurrentIndex(0); // this gives the error
    6. }
    To copy to clipboard, switch view to plain text mode 

    I'm not able to get access to the ui pointer in my derived class. I got the error
    "invalid use of incomplete type 'class Ui::ui_calib_base'
    forward declaration of 'class Ui::ui_calib_base'

    I have move the ui pointer to protected, but have no access to it in my derived class? What i'm doing wrong?
    Thx

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Subclass from Qt Ui Form Class, invalid use of incomplete type

    Seems like you are deliberately setting out to confuse the heck out of yourself by using the name "ui_calib_base" for both the class declared in the "Ui" namespace as well as the class in the global namespace that derives from QWidget. Why not rename the QWidget class to something more sensible, like simply "calib_base" or "calib_base_widget". Geez.

    If the code you posted is your actual code, then I think your mistake is that you are including the wrong header file: <ui/ui_calib_base.h> in calib_analog.h, where you should be including "ui_calib_base.h" (the header for the QWidget class) instead. See how confusing this is with this poor choice of names?

    In ui_calib_base.h (the QWidget class header), you should be #including <ui/ui_calib_base.h> instead of using a forward declaration.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Subclass from Qt Ui Form Class, invalid use of incomplete type

    The includes are all Ok, to make it clear:

    The base class is a Qt Form Class located in subdir ui/
    ui/ui_calib_base.h
    ui/ui_calib_base.cpp
    ui/ui_calib_base.ui

    This is the derived class from the base class
    calib_analog.h
    calib_analog.cpp

    In my calib_analog i have no access to the ui pointer of the base class although i moved it into the protected section in "ui/ui_calib_base.h".

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Subclass from Qt Ui Form Class, invalid use of incomplete type

    In my calib_analog i have no access to the ui pointer of the base class although i moved it into the protected section in "ui/ui_calib_base.h".
    You -do- have access to it. As I said, this code:

    Qt Code:
    1. namespace Ui {
    2. class ui_calib_base;
    3. }
    To copy to clipboard, switch view to plain text mode 

    only declares a forward reference to the Ui:: ui_calib_base class; it does not define the class. You need to include that actual header file that defines the Ui:: class. This file is created by MOC when it processes your .ui file.

    The compiler is telling you that you are trying to use methods and variables of the Ui:: class in a place where all it knows is the name of the class (via the forward declaration) because it hasn't seen the actual definition. That's an "invalid use of an incomplete type".
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. invalid use of incomplete type 'struct MSG'
    By libed in forum Qt Programming
    Replies: 5
    Last Post: 21st February 2019, 12:32
  2. Replies: 1
    Last Post: 11th October 2016, 18:49
  3. invalid use of incomplete type 'class QWebFrame'
    By rahulvishwakarma in forum Qt Programming
    Replies: 1
    Last Post: 30th April 2016, 16:46
  4. Replies: 9
    Last Post: 29th August 2010, 14:30
  5. error: invalid use of incomplete type 'struct QMetaEnum'
    By dyngoman in forum Qt Programming
    Replies: 3
    Last Post: 12th March 2010, 13:38

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.