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. QFont error on compile time
Qt 6.11 is out! See what's new in the release blog

QFont error on compile time

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 783 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.
  • J Offline
    J Offline
    jkwok678
    wrote on last edited by
    #1

    What I want to have is for each custom text object to have it's only QFont. Why is this not allowed in the header file or in a constructor?

        QFont font;
    

    Error given is:
    element.cpp:37:107: error: variable has incomplete type 'QFont'
    qmetatype.h:2090:1: note: forward declaration of 'QFont'
    qmetatype.h:155:18: note: expanded from macro 'QT_FOR_EACH_STATIC_GUI_CLASS'

    Why is this allowed?

        QFont* font;
    
    JonBJ 1 Reply Last reply
    0
    • J jkwok678

      What I want to have is for each custom text object to have it's only QFont. Why is this not allowed in the header file or in a constructor?

          QFont font;
      

      Error given is:
      element.cpp:37:107: error: variable has incomplete type 'QFont'
      qmetatype.h:2090:1: note: forward declaration of 'QFont'
      qmetatype.h:155:18: note: expanded from macro 'QT_FOR_EACH_STATIC_GUI_CLASS'

      Why is this allowed?

          QFont* font;
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @jkwok678
      For a start you need to #include <QFont> to allow for QFont f.

      OTOH, it's enough to go class QFont;, with no #include, to be allowed to go QFont *f.

      My guess is your order of includes put you in the second situation, doubtless from the

      qmetatype.h:2090:1: note: forward declaration of 'QFont'

      1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @jkwok678 said in QFont error on compile time:

        Why is this allowed?

        C++ basics - the compiler needs to know the size of the type when it sees it. Since the size of a pointer is known, forward declaring a pointer is possible.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        2

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved