Invalid use of incomplete type 'class Ui::MainWindow' in default Qt Creator Hello world with QTabWidget added to mainwindow.ui
-
To recreate:
- Create a new Qt Widgets application with a mainwindow.ui form and class etc.
- Add a QTabWidget from the form designer to the canvas (QMainWindow)
- Right-click on the QTabWidget and Layout > On a Grid.
- The default name is
tabWidget
as you can see in the properties panel. Leave the name alone. - Create a member function in your QMainWindow class (the class template was already generated by Qt in step 1).
- 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 ofui
. So how do you accessui
's members as created in the form designer? -
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 callui->tabWidget
in a .cpp defined function. -
To recreate:
- Create a new Qt Widgets application with a mainwindow.ui form and class etc.
- Add a QTabWidget from the form designer to the canvas (QMainWindow)
- Right-click on the QTabWidget and Layout > On a Grid.
- The default name is
tabWidget
as you can see in the properties panel. Leave the name alone. - Create a member function in your QMainWindow class (the class template was already generated by Qt in step 1).
- 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 ofui
. So how do you accessui
's members as created in the form designer?@enjoysmath
Please paste (not screenshot) the.cpp
file you show, at least up to line #20. We need to see thei#include
s at the start.Similarly, paste from your
mainwindow.h
, at least up to line #22-ish. -
Found reason: You can't do that
addTabWidget
definition in the class declartion, because of C++ limitation of forward class declarations I can only callui->tabWidget
in a .cpp defined function.@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 callui->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 -
This post is deleted!