Invisible text in QTextEdit



  • I am learning Qt and running examples from Qt SDK 5.9.1. I run the code below and write inside QTextEdit but no text appears. Cursor moves as I write but no text is shown. Window title text is shown.

     int main(int argc, char *argv[])
     {
       QApplication app(argc, argv);
    
       QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
       std::cout << font.toString().toUtf8().constData();
       QFontDatabase database;
       QStringList fam = database.families();
       app.setFont(QFont("Ubuntu", 11, QFont::Normal, false));
    
       QTextEdit textEdit; 
       textEdit.show();
    
       return app.exec();
     }
    

    I tried to get system font using QFontDatabase but it didn't work:

    app.setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
    

    This doesn't do anything with any of enum values including QFontDatabase::GeneralFont

    QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
    

    font prints Sans Serif,9,-1,5,50,0,0,0,0,00.

    QFontDatabase database;
    QStringList fam = database.families();
    

    fam size is zero.

    I built qt from source using the instructions here. How can I fix this and set the app font to default ubuntu font?

    My specs:
    Ubuntu 16.04
    Qt 5.9.1


  • Moderators

    @Alp-Hancioglu Does it work if you don't set any font? Do other Qt apps work (like VCL)?
    Also: how did you install Qt?



  • It doesn't work if I don't set any font.
    Do you mean VLC media player? I just installed VLC and it also doesn't display any text. It only displays window headers and menu items.
    I built qt from source as I said in my post.



  • Hmm.. according to your code:
    When you do not set a text in the QTextEdit-Control (textEdit.setPlainText)
    there will be no visible text in the control!



  • @karlheinzreichel I don't understand what you mean exactly but textEdit.append("some"); call doesn't display any text either. It moves the cursor but no text is shown.



  • @Alp-Hancioglu
    in your code above there is no append (or did I miss something ?)



  • @karlheinzreichel I tried the append call at some point but forgot to add it to the post. The issue seems much more bigger than QTextEdit though as there is also no text shown in VLC media player.



  • As you build qt from scratch, the question :
    Have you installed the libconfig libraries before ... ?

    (probably not)

    regards
    karl-heinz



  • @karlheinzreichel I didn't explicitly install libconfig library myself. I don't know if other program installed it as prerequisite.
    In order to build, I downloaded qt-everywhere-opensource-src-5.9.1.tar.xz file and extracted it.
    Then called ./configure and make on bash.



  • So I would reccomend to check the build requierments for QT
    (see http://doc.qt.io/qt-5/linux-requirements.html)
    before building the qt libs

    regards
    Karl-Heinz


  • Moderators

    @Alp-Hancioglu Try to start your app with QT_DEBUG_PLUGINS environment variable set and check the output in the console. Looks like something is wrong with your system.



  • @jsulm I set the env variable and there are no errors listed. Just a bunch of plugin metadata loads. Should I look for something?


  • Moderators

    @Alp-Hancioglu Are there any errors/warnings?



  • @jsulm There are no errors or warnings.



  • @karlheinzreichel I checked every package and its dev version listed in requirements list and they are all installed and at newest version so there is no need to install or upgrade any of them. Some packages don't have the exact same name on my machine: libfontconfig is listed as libfontconfig1 on mine, libfreetype is listed as libfreetype6 on mine but the descriptions match.
    I built Qt a week ago so they were most probably at newest version at time of compilation so I don't think they are related to the issue I have.


  • Moderators

    @Alp-Hancioglu If you execute configure script before building Qt you will get a summary what was found and enabled. You can execute configure again with -v parameter and see whether fontconfig was really enabled.



  • @jsulm Thanks for the continued support jsulm.

    I used ./configure -v and saw that fontconfig is disabled in build options:

    Qt Gui:
      Accessibility .......................... yes
      FreeType ............................... yes
        Using system FreeType ................ no
      HarfBuzz ............................... yes
        Using system HarfBuzz ................ no
      Fontconfig ............................. no
    

    Then I used ./configure -v -fontconfig to enable it but it didn't work with error:

    ERROR: Feature 'fontconfig' was enabled, but the pre-condition '!config.win32 && !config.darwin && features.system-freetype && libs.fontconfig' failed.
    

    Then I run following to make sure libfontconfig is installed:

    sudo apt install libfontconfig1
    [sudo] password for alp: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    libfontconfig1 is already the newest version (2.11.94-0ubuntu1.1).
    0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
    

    I also run ./configure -system-freetype -fontconfig but it doesn't make a difference with resulting errors:

    ERROR: Feature 'system-freetype' was enabled, but the pre-condition 'features.freetype && libs.freetype' failed.
    
    ERROR: Feature 'fontconfig' was enabled, but the pre-condition '!config.win32 && !config.darwin && features.system-freetype && libs.fontconfig' failed.
    

    Make sure freetype is installed:

    sudo apt install libfreetype6
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    libfreetype6 is already the newest version (2.6.1-0.1ubuntu2.3).
    0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.

  • Moderators

    @Alp-Hancioglu You need to install the dev package for fontconfig. Something like libfontconfig1-dev.



  • @jsulm It is already installed:

    sudo apt install libfontconfig1-dev
    [sudo] password for alp: 
    Reading package lists... Done
    Building dependency tree       
    Reading state information... Done
    libfontconfig1-dev is already the newest version (2.11.94-0ubuntu1.1).
    0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
    

    I checked every dev package in the requirements list and they are all installed with newest versions


  • Moderators

    @Alp-Hancioglu If you execute configure with -v you should get more output. Can you post it here?



  • I uninstalled Qt build with make uninstall and then fonts in VLC appeared. I am guessing Qt code in VLC was referencing Qt build libs in /usr/local/Qt-5.9.1/lib directory, which are deleted after uninstall, and this was causing the missing font in VLC. After uninstall VLC started referencing libs in /usr/lib/x86_64-linux-gnu/ which work and fonts appeared.

    I tried compiling against headers and libs in qt-everywhere-opensource-src-5.9.1 directory, which is downloaded from qt website:

    g++ -Wall -fPIC -c -g -I/home/alp/Downloads/qt-everywhere-opensource-src-5.9.1/qtbase/include -I/home/alp/Downloads/qt-everywhere-opensource-src-5.9.1/qtbase/include/QtWidgets main.cpp -o main.o
    g++ -g -Wl,--trace main.o ext/printer.o -o main -L/home/alp/Downloads/qt-everywhere-opensource-src-5.9.1/qtbase/lib -lQt5Gui -lQt5Core -lQt5Widgets
    /usr/bin/ld: mode elf_x86_64
    /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/crt1.o
    /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/crti.o
    /usr/lib/gcc/x86_64-linux-gnu/6/crtbegin.o
    main.o
    ext/printer.o
    -lQt5Gui (/home/alp/Downloads/qt-everywhere-opensource-src-5.9.1/qtbase/lib/libQt5Gui.so)
    -lQt5Core (/home/alp/Downloads/qt-everywhere-opensource-src-5.9.1/qtbase/lib/libQt5Core.so)
    -lQt5Widgets (/home/alp/Downloads/qt-everywhere-opensource-src-5.9.1/qtbase/lib/libQt5Widgets.so)
    -lstdc++ (/usr/lib/gcc/x86_64-linux-gnu/6/libstdc++.so)
    /lib/x86_64-linux-gnu/libm.so.6
    /lib/x86_64-linux-gnu/libmvec.so.1
    libgcc_s.so.1 (/usr/lib/gcc/x86_64-linux-gnu/6/libgcc_s.so.1)
    /lib/x86_64-linux-gnu/libc.so.6
    (/usr/lib/x86_64-linux-gnu/libc_nonshared.a)elf-init.oS
    /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
    /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
    libgcc_s.so.1 (/usr/lib/gcc/x86_64-linux-gnu/6/libgcc_s.so.1)
    /usr/lib/gcc/x86_64-linux-gnu/6/crtend.o
    /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/crtn.o

    When I run with ./main following errors appear:

    ./main: /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5: version Qt_5' not found (required by ./main) ./main: /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5: versionQt_5' not found (required by ./main)
    ./main: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: version Qt_5.9' not found (required by ./main) ./main: /usr/lib/x86_64-linux-gnu/libQt5Core.so.5: versionQt_5' not found (required by ./main)

    which makes me guess that libs in qt-everywhere-opensource-src-5.9.1 are empty and g++ references the libs in x86_64-linux-gnu which are not the latest version 5.9 as expected.



  • @jsulm I don't notice much difference with -v but here it is.

    ./configure -system-freetype -fontconfig -v

    • cd qtbase
    • /home/alp/Downloads/qt-everywhere-opensource-src-5.9.1/qtbase/configure -top-level -system-freetype -fontconfig -v
      Creating qmake...
      make: Nothing to be done for 'first'.
      Command line: -system-freetype -fontconfig -v

    Selecting Qt Edition.

    Type 'c' if you want to use the Commercial Edition.
    Type 'o' if you want to use the Open Source Edition.

    Which edition of Qt do you want to use? o

    This is the Qt Open Source Edition.

    You are licensed to use this software under the terms of
    the GNU Lesser General Public License (LGPL) version 3
    or the GNU General Public License (GPL) version 2.

    Type 'L' to view the GNU Lesser General Public License version 3 (LGPLv3).
    Type 'G' to view the GNU General Public License version 2 (GPLv2).
    Type 'y' to accept this license offer.
    Type 'n' to decline this license offer.

    Do you accept the terms of either license? y

    Running configuration tests...
    Done running configuration tests.

    Configure summary:

    Build type: linux-g++ (x86_64, CPU features: mmx sse sse2)
    Configuration: use_gold_linker sse2 sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples enable_new_dtags f16c largefile precompile_header shared rpath release c++11 c++14 c++1z concurrent dbus mremap reduce_exports reduce_relocations stl
    Build options:
    Mode ................................... release
    Optimize release build for size ........ no
    Building shared libraries .............. yes
    Using C++ standard ..................... C++1z
    Using gold linker ...................... yes
    Using new DTAGS ........................ yes
    Using precompiled headers .............. yes
    Using LTCG ............................. no
    Target compiler supports:
    SSE .................................. SSE2 SSE3 SSSE3 SSE4.1 SSE4.2
    AVX .................................. AVX AVX2 F16C
    AVX512 ............................... F ER CD PF DQ BW VL IFMA VBMI
    Build parts ............................ libs examples tools
    Qt modules and options:
    Qt Concurrent .......................... yes
    Qt D-Bus ............................... yes
    Qt D-Bus directly linked to libdbus .... no
    Qt Gui ................................. yes
    Qt Network ............................. yes
    Qt Sql ................................. yes
    Qt Testlib ............................. yes
    Qt Widgets ............................. yes
    Qt Xml ................................. yes
    Support enabled for:
    Using pkg-config ....................... yes
    QML debugging .......................... yes
    udev ................................... no
    Using system zlib ...................... yes
    Qt Core:
    DoubleConversion ....................... yes
    Using system DoubleConversion ........ no
    GLib ................................... no
    iconv .................................. yes
    ICU .................................... no
    Logging backends:
    journald ............................. no
    syslog ............................... no
    slog2 ................................ no
    Using system PCRE2 ..................... no
    Qt Network:
    getaddrinfo() .......................... yes
    getifaddrs() ........................... yes
    IPv6 ifname ............................ yes
    libproxy ............................... no
    OpenSSL ................................ no
    Qt directly linked to OpenSSL ........ no
    SCTP ................................... no
    Use system proxies ..................... yes
    Qt Gui:
    Accessibility .......................... yes
    FreeType ............................... yes
    Using system FreeType ................ no
    HarfBuzz ............................... yes
    Using system HarfBuzz ................ no
    Fontconfig ............................. no
    Image formats:
    GIF .................................. yes
    ICO .................................. yes
    JPEG ................................. yes
    Using system libjpeg ............... no
    PNG .................................. yes
    Using system libpng ................ no
    EGL .................................... no
    OpenVG ................................. no
    OpenGL:
    Desktop OpenGL ....................... yes
    OpenGL ES 2.0 ........................ no
    OpenGL ES 3.0 ........................ no
    OpenGL ES 3.1 ........................ no
    Session Management ..................... yes
    Features used by QPA backends:
    evdev .................................. yes
    libinput ............................... no
    INTEGRITY HID .......................... no
    mtdev .................................. no
    tslib .................................. no
    xkbcommon-evdev ........................ no
    QPA backends:
    DirectFB ............................... no
    EGLFS .................................. no
    LinuxFB ................................ yes
    VNC .................................... yes
    Mir client ............................. no
    X11:
    Using system-provided XCB libraries .. no
    EGL on X11 ........................... no
    Xinput2 .............................. no
    XCB XKB .............................. yes
    XLib ................................. yes
    XCB render ........................... yes
    XCB GLX .............................. yes
    XCB Xlib ............................. yes
    Using system-provided xkbcommon ...... no
    Qt Widgets:
    GTK+ ................................... no
    Styles ................................. Fusion Windows
    Qt PrintSupport:
    CUPS ................................... no
    Qt Sql:
    DB2 (IBM) .............................. no
    InterBase .............................. no
    MySql .................................. no
    OCI (Oracle) ........................... no
    ODBC ................................... no
    PostgreSQL ............................. no
    SQLite2 ................................ no
    SQLite ................................. yes
    Using system provided SQLite ......... no
    TDS (Sybase) ........................... no
    Qt SerialBus:
    Socket CAN ............................. yes
    Socket CAN FD .......................... yes
    QtXmlPatterns:
    XML schema support ..................... yes
    Qt QML:
    QML interpreter ........................ yes
    QML network support .................... yes
    Qt Quick:
    Direct3D 12 ............................ no
    AnimatedImage item ..................... yes
    Canvas item ............................ yes
    Support for Qt Quick Designer .......... yes
    Flipable item .......................... yes
    GridView item .......................... yes
    ListView item .......................... yes
    Path support ........................... yes
    PathView item .......................... yes
    Positioner items ....................... yes
    ShaderEffect item ...................... yes
    Sprite item ............................ yes
    Qt Gamepad:
    SDL2 ................................... no
    Qt 3D:
    Assimp ................................. yes
    System Assimp .......................... no
    Output Qt3D Job traces ................. no
    Output Qt3D GL traces .................. no
    Qt 3D GeometryLoaders:
    Autodesk FBX ........................... no
    Qt Wayland Client ........................ no
    Qt Wayland Compositor .................... no
    Qt Bluetooth:
    BlueZ .................................. no
    BlueZ Low Energy ....................... no
    Linux Crypto API ....................... no
    Qt Sensors:
    sensorfw ............................... no
    Qt Multimedia:
    ALSA ................................... no
    GStreamer 1.0 .......................... no
    GStreamer 0.10 ......................... no
    Video for Linux ........................ yes
    OpenAL ................................. no
    PulseAudio ............................. no
    Resource Policy (libresourceqt5) ....... no
    Windows Audio Services ................. no
    DirectShow ............................. no
    Windows Media Foundation ............... no
    Qt Quick Controls 2:
    Styles ................................. Default Material Universal
    Qt Quick Templates 2:
    Hover support .......................... yes
    Multi-touch support .................... yes
    Qt Location:
    Gypsy GPS Daemon ....................... no
    WinRT Geolocation API .................. no
    Qt WebEngine:
    Embedded build ......................... no
    Pepper Plugins ......................... yes
    Printing and PDF ....................... yes
    Proprietary Codecs ..................... no
    Spellchecker ........................... yes
    WebRTC ................................. yes
    Using system ninja ..................... no
    ALSA ................................... no
    PulseAudio ............................. no
    System libraries:
    ICU .................................. no
    libwebp and libwebpdemux ............. no
    Opus ................................. no
    ffmpeg ............................... no

    Note: Also available for Linux: linux-clang linux-icc

    Note: Disabling Linux Accessibility Bridge: D-Bus is missing.

    Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.

    ERROR: Feature 'system-freetype' was enabled, but the pre-condition 'features.freetype && libs.freetype' failed.

    ERROR: Feature 'fontconfig' was enabled, but the pre-condition '!config.win32 && !config.darwin && features.system-freetype && libs.fontconfig' failed.


  • Moderators

    @Alp-Hancioglu said in Invisible text in QTextEdit:

    Configure summary

    There must be much more output before "Configure summary".
    You should try it again from a clean state (you built before, so unzip source archive again).



  • @jsulm I unzipped and run ./configure -system-freetype -fontconfig -v again and everything seems ok now:

    Qt Gui:
      Accessibility .......................... yes
      FreeType ............................... yes
        Using system FreeType ................ yes
      HarfBuzz ............................... yes
        Using system HarfBuzz ................ yes
      Fontconfig ............................. yes
    

    Do you still need the debug info? I don't think its necessary now. I don't know what caused previous fails. I will "make" and "make install" and try again now.


  • Moderators

    @Alp-Hancioglu OK. To avoid such issues you should do "out of source builds" in the future. This means: create a directory OUTSIDE of the source directory, change to this directory, call configure from there and make.
    Lets say you're in a directory where the subdirectory with Qt sources is located:

    mkdir build
    cd build
    ../qt/configure ...
    make
    make install
    

    This way your source tree will stay unchanged and if you want to rebuild just delete the content of the build directory and build again.



  • I built qt and font show up now. Thanks a lot jsulm for the support.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.