Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Invalid use of incomplete type 'class Ui::MainWindow' in default Qt Creator Hello world with QTabWidget added to mainwindow.ui



  • To recreate:

    1. Create a new Qt Widgets application with a mainwindow.ui form and class etc.
    2. Add a QTabWidget from the form designer to the canvas (QMainWindow)
    3. Right-click on the QTabWidget and Layout > On a Grid.
    4. The default name is tabWidget as you can see in the properties panel. Leave the name alone.
    5. Create a member function in your QMainWindow class (the class template was already generated by Qt in step 1).
    6. Within that function, call ui->tabWidget.

    The line should be highlighted red indicating errors but you can also see it when you build in the build error output panel.

    invalid use of incomplete type 'class Ui::MainWindow'

    Is the first error, and other places when they don't say this will say that tabWidget is not a member of ui. So how do you access ui's members as created in the form designer?

    eaa025f1-0474-45eb-bfb0-ad1606626609-image.png



  • This post is deleted!


  • Found reason: You can't do that addTabWidget definition in the class declartion, because of C++ limitation of forward class declarations I can only call ui->tabWidget in a .cpp defined function.



  • @enjoysmath
    Please paste (not screenshot) the .cpp file you show, at least up to line #20. We need to see the i#includes at the start.

    Similarly, paste from your mainwindow.h, at least up to line #22-ish.



  • @enjoysmath said in Invalid use of incomplete type 'class Ui::MainWindow' in default Qt Creator Hello world with QTabWidget added to mainwindow.ui:

    Found reason: You can't do that addTabWidget definition in the class declartion, because of C++ limitation of forward class declarations I can only call ui->tabWidget in a .cpp defined function.

    This is not accurate, you can use it wherever you want but you have to #include "ui_mainwindow.h" first


Log in to reply