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. [SOLVED] Qt Creator not recognising Widgets despite inlcuding all necessary includes
QtWS25 Last Chance

[SOLVED] Qt Creator not recognising Widgets despite inlcuding all necessary includes

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 3.3k 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.
  • D Offline
    D Offline
    DeanQt
    wrote on last edited by
    #1

    Qt creator doesnt recognise QTreeWidget when typed in. I literally included all header files:
    @#include <QDialog>
    #include <QtCore>
    #include <QtGui>
    #include <QWidget>@

    And even the tutorial Im watching had LESS exhaustive header files and worked for them (they missed the QWidget include)

    I do understand that:
    @#include <QTreeWidgetItem>@
    is one way of making sure the compiler includes the TreeWidgetItem, which does work if I include it, but I dont see why that needs to be in there; I included QWidget which includes ALL widgets.

    Infact in the tutorial the only includes were @#include <QDialog>
    #include <QtCore>
    #include <QtGui>@
    i.e. it didnt even include QWidget and the tutorial pulled it off!

    Please can anyone explain why this is so???

    1 Reply Last reply
    0
    • A Offline
      A Offline
      arnolddumas
      wrote on last edited by
      #2

      The thing is the tutorial you're reading was written for Qt4. In Qt5, some includes must be changed.

      In Qt4 the <QtGui> include was used to make all the widgets known by the compiler. But in Qt5, the widgets (QLineEdit, QTextEdit ....) have been moved to a brand new module called 'widgets'. Therefore you'll need to replace QtGui by QtWidgets

      Notice there's a 's' at the end of the QtWidgets include.

      So your includes should now look like that :

      @#include <QtCore>
      #include <QtWidgets>
      @

      Also notice that QDialog is already included with QtWidgets.

      And don't forget to add the new 'widgets' module in your *.pro file.

      Now everything should just works fine.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        bq. I included QWidget which includes ALL widgets

        Including <QWidget> gives the compiler a complete declaration of the QWidget base class. It does not generally include a declaration of sub-classes like QLabel, QTextEdit etc.; they have their own includes.

        Including <QtGui> (Qt4) or <QtWidgets> (Qt5) does include complete declarations for all widgets. You should not get into the habit of including all of the GUI includes for non-trivial project unless you are particularly enamoured of longer-than-necessary build times.

        It's not clear what you mean by, "Qt creator doesnt recognise QTreeWidget when typed in." Qt Creator cannot perform auto-complete functions for classes without a complete declaration of a class. If you only have a forward declaration, perhaps provided by a related include that doesn't itself require a full declaration, then Creator knows only that the class exists but not how it is built so it cannot offer completion for member functions etc. For example, the QWidget include declares the existence but not the content of class QLayout, QVariant, QStyle etc.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DeanQt
          wrote on last edited by
          #4

          Thanks guys, I included QtWidgets and it seems to work!

          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