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. Invalid use of incomplete type 'class Ui::MainWindow' in default Qt Creator Hello world with QTabWidget added to mainwindow.ui

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

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.2k 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.
  • E Offline
    E Offline
    enjoysmath
    wrote on 2 Jun 2021, 16:34 last edited by enjoysmath 6 Feb 2021, 16:55
    #1

    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

    J 1 Reply Last reply 2 Jun 2021, 17:00
    0
    • E Offline
      E Offline
      enjoysmath
      wrote on 2 Jun 2021, 16:47 last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • E Offline
        E Offline
        enjoysmath
        wrote on 2 Jun 2021, 16:57 last edited by
        #3

        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.

        V 1 Reply Last reply 2 Jun 2021, 17:02
        0
        • E enjoysmath
          2 Jun 2021, 16:34

          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

          J Offline
          J Offline
          JonB
          wrote on 2 Jun 2021, 17:00 last edited by JonB 6 Feb 2021, 17:02
          #4

          @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.

          1 Reply Last reply
          1
          • E enjoysmath
            2 Jun 2021, 16:57

            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.

            V Offline
            V Offline
            VRonin
            wrote on 2 Jun 2021, 17:02 last edited by
            #5

            @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

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            4
            • N Offline
              N Offline
              nokede2571
              wrote on 16 Aug 2024, 12:53 last edited by
              #6
              This post is deleted!
              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