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
Forum Updated to NodeBB v4.3 + New Features

QFont error on compile time

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 414 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 14 Jul 2020, 16:12 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;
    
    J 1 Reply Last reply 14 Jul 2020, 16:14
    0
    • J jkwok678
      14 Jul 2020, 16:12

      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;
      
      J Offline
      J Offline
      JonB
      wrote on 14 Jul 2020, 16:14 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
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 14 Jul 2020, 16:53 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

        1/3

        14 Jul 2020, 16:12

        • Login

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