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. Qt5 'QFontDatabase' class
Qt 6.11 is out! See what's new in the release blog

Qt5 'QFontDatabase' class

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.1k Views 1 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.
  • F Offline
    F Offline
    feri
    wrote on last edited by
    #1

    HI
    I installed Qt5 in ubuntu 20.04 using the file:
    qt-unified-linux-x64-4.0.1-1-online.run
    Some libraries were missing to compile the program and I installed them with these commands:
    sudo apt-get update
    sudo apt-get install libqt5script5
    sudo apt-get install qtscript5-dev
    sudo apt-get install gcc-avr
    sudo apt install libqt5serialport5-dev
    sudo apt-get install -y libqt5svg5-dev

    Now I would like to use the 'QFontDatabase' class but when I insert in the code:
    #include <QFontDatabase>
    The compiler tells me: 'QFontDatabase' file not found
    How can I install this class?
    Thank you
    Greetings
    ​

    JonBJ 1 Reply Last reply
    0
    • F feri

      HI
      I installed Qt5 in ubuntu 20.04 using the file:
      qt-unified-linux-x64-4.0.1-1-online.run
      Some libraries were missing to compile the program and I installed them with these commands:
      sudo apt-get update
      sudo apt-get install libqt5script5
      sudo apt-get install qtscript5-dev
      sudo apt-get install gcc-avr
      sudo apt install libqt5serialport5-dev
      sudo apt-get install -y libqt5svg5-dev

      Now I would like to use the 'QFontDatabase' class but when I insert in the code:
      #include <QFontDatabase>
      The compiler tells me: 'QFontDatabase' file not found
      How can I install this class?
      Thank you
      Greetings
      ​

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @feri
      Are you aware that your Ubuntu 20.04 has all of Qt available from apt? I don't know how that compares to you seemingly mixing with stuff from Qt online. But I do not recall having to install anything additional to get QFontDatabase.

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

        @feri

        @feri said in Qt5 'QFontDatabase' class:

        qt-unified-linux-x64-4.0.1-1-online.run

        Why such an ancient Online Installer? At time of writing the Linux Online Installer was version 4.6.1. Through it you can access Qt 5.15.2, including a deprecated Qt Script but not QSerialPort.

        Ubuntu's 20.04 repository contains Qt 5.12.8: qt5-default
        You are better off sticking to one or the other. The distro version is more complete (and more recent for Ubuntu 22.04 (qtbase5-dev qt5-qmake))

        @feri said in Qt5 'QFontDatabase' class:

        Now I would like to use the 'QFontDatabase' class but when I insert in the code:
        #include <QFontDatabase>
        The compiler tells me: 'QFontDatabase' file not found
        How can I install this class?

        QFontDatabase is part of any default Qt installation.
        The include will be found if the relevant settings are made in your qmake PRO file or CMakeLists.txt.

        @feri said in Qt5 'QFontDatabase' class:

        Some libraries were missing to compile the program and I installed them with these commands:
        sudo apt-get install gcc-avr

        Nothing at all to do with Qt. If you are trying to cross-compile for an AVR microcontroller then you will not get far.

        F 1 Reply Last reply
        1
        • C ChrisW67

          @feri

          @feri said in Qt5 'QFontDatabase' class:

          qt-unified-linux-x64-4.0.1-1-online.run

          Why such an ancient Online Installer? At time of writing the Linux Online Installer was version 4.6.1. Through it you can access Qt 5.15.2, including a deprecated Qt Script but not QSerialPort.

          Ubuntu's 20.04 repository contains Qt 5.12.8: qt5-default
          You are better off sticking to one or the other. The distro version is more complete (and more recent for Ubuntu 22.04 (qtbase5-dev qt5-qmake))

          @feri said in Qt5 'QFontDatabase' class:

          Now I would like to use the 'QFontDatabase' class but when I insert in the code:
          #include <QFontDatabase>
          The compiler tells me: 'QFontDatabase' file not found
          How can I install this class?

          QFontDatabase is part of any default Qt installation.
          The include will be found if the relevant settings are made in your qmake PRO file or CMakeLists.txt.

          @feri said in Qt5 'QFontDatabase' class:

          Some libraries were missing to compile the program and I installed them with these commands:
          sudo apt-get install gcc-avr

          Nothing at all to do with Qt. If you are trying to cross-compile for an AVR microcontroller then you will not get far.

          F Offline
          F Offline
          feri
          wrote on last edited by
          #4

          HI
          Thank you for answering me.
          By "qmake PRO file" you mean the project file "appname.pro" and if that's what I need to add an entry like this "QT += widgets".
          But what exactly should I write, I'm not an expert in Qt.
          Thank you
          Greetings

          C SGaistS 2 Replies Last reply
          0
          • F feri

            HI
            Thank you for answering me.
            By "qmake PRO file" you mean the project file "appname.pro" and if that's what I need to add an entry like this "QT += widgets".
            But what exactly should I write, I'm not an expert in Qt.
            Thank you
            Greetings

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            Yes. Minimal example.

            test.pro:

            QT = widgets
            CONFIG += c++17
            SOURCES += \
                    main.cpp
            

            main.cpp:

            #include <QApplication>
            #include <QTextEdit>
            #include <QFontDatabase>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
            
                QTextEdit edit;
                const QStringList list = QFontDatabase::families();
                edit.setText(list.join('\n'));
                edit.show();
                return a.exec();
            }
            

            Build:

            qmake 
            make
            ./test
            
            F 1 Reply Last reply
            1
            • F feri

              HI
              Thank you for answering me.
              By "qmake PRO file" you mean the project file "appname.pro" and if that's what I need to add an entry like this "QT += widgets".
              But what exactly should I write, I'm not an expert in Qt.
              Thank you
              Greetings

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Yes, that's that file and its literally that line that you can add.

              Since you are new to that, you should check the qmake manual which is pretty extensive.

              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
              • C ChrisW67

                Yes. Minimal example.

                test.pro:

                QT = widgets
                CONFIG += c++17
                SOURCES += \
                        main.cpp
                

                main.cpp:

                #include <QApplication>
                #include <QTextEdit>
                #include <QFontDatabase>
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                
                    QTextEdit edit;
                    const QStringList list = QFontDatabase::families();
                    edit.setText(list.join('\n'));
                    edit.show();
                    return a.exec();
                }
                

                Build:

                qmake 
                make
                ./test
                
                F Offline
                F Offline
                feri
                wrote on last edited by
                #7

                @ChrisW67
                Thanks I succeeded I got the list of installed fonts using your example with a small modification.
                I use QtCreator.

                int main(int argc, char *argv[])
                {
                QApplication a(argc, argv);
                QFontDatabase dat;
                QTextEdit edit;
                const QStringList list = dat.families();
                edit.setText(list.join('\n'));
                edit.show();
                return a.exec();
                }
                Greetings

                C 1 Reply Last reply
                0
                • F feri

                  @ChrisW67
                  Thanks I succeeded I got the list of installed fonts using your example with a small modification.
                  I use QtCreator.

                  int main(int argc, char *argv[])
                  {
                  QApplication a(argc, argv);
                  QFontDatabase dat;
                  QTextEdit edit;
                  const QStringList list = dat.families();
                  edit.setText(list.join('\n'));
                  edit.show();
                  return a.exec();
                  }
                  Greetings

                  C Offline
                  C Offline
                  ChrisW67
                  wrote on last edited by
                  #8

                  @feri Excellent. I had not recognised the Qt5-Qt6 differences.

                  1 Reply Last reply
                  0
                  • F feri has marked this topic as solved on

                  • Login

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