Invalid use of incomplete type 'class Ui::MainWindow' in default Qt Creator Hello world with QTabWidget added to mainwindow.ui
-
wrote on 2 Jun 2021, 16:34 last edited by enjoysmath 6 Feb 2021, 16:55
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? -
wrote on 2 Jun 2021, 16:47 last edited byThis post is deleted!
-
wrote on 2 Jun 2021, 16:57 last edited by
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?wrote on 2 Jun 2021, 17:00 last edited by JonB 6 Feb 2021, 17:02@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.wrote on 2 Jun 2021, 17:02 last edited by@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 -
wrote on 16 Aug 2024, 12:53 last edited byThis post is deleted!