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. static const QFont using QFontDatabase?
Forum Updated to NodeBB v4.3 + New Features

static const QFont using QFontDatabase?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 4 Posters 2.5k Views 4 Watching
  • 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.
  • SeeLookS SeeLook

    You may init any static member after font is loaded.

    P Offline
    P Offline
    Pippin
    wrote on last edited by
    #3

    @SeeLook I'm sorry what? I'm not sure I understood what you were trying to say. Keep in mind that I'd like the static member to be const.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      Hi,

      Why do you need a static QFont ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        Why do you need a static QFont ?

        P Offline
        P Offline
        Pippin
        wrote on last edited by
        #5

        Hi @SGaist,

        Basically I need a global variable, and I don't intend to change it once I declared it.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #6

          That's what I thought but what would be the use of that global QFont ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          0
          • SGaistS SGaist

            That's what I thought but what would be the use of that global QFont ?

            P Offline
            P Offline
            Pippin
            wrote on last edited by Pippin
            #7

            @SGaist It would be used whenever a few functions are run. I'm just trying to load it once and for all, rather than load it every time these functions are called. The use is drawing texts on a QImage.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Are these functions in separated classes ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pippin
                wrote on last edited by
                #9

                No they are all in that same class.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  Then why not just make it a member and load it at construction time ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  P 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Then why not just make it a member and load it at construction time ?

                    P Offline
                    P Offline
                    Pippin
                    wrote on last edited by
                    #11

                    @SGaist I could do that, but it's the same font for all instances. So it would be kind of a waste of space.

                    kshegunovK 1 Reply Last reply
                    0
                    • SeeLookS Offline
                      SeeLookS Offline
                      SeeLook
                      wrote on last edited by
                      #12

                      Simply add static init() method to the class where private static QFont is done and give access to it through const method

                      QFont myFont () const { return m_font;  }
                      
                      1 Reply Last reply
                      0
                      • P Pippin

                        @SGaist I could do that, but it's the same font for all instances. So it would be kind of a waste of space.

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #13

                        @Pippin

                        So it would be kind of a waste of space.

                        Hello,
                        I suggest answering these two questions for your own peace of mind:

                        1. How much space would you expect to save if you put it in a static variable?
                        2. What do you gain or lose by making it a static and is it worth the effort (in work time/planning time)?

                        Kind regards.

                        Read and abide by the Qt Code of Conduct

                        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