Important: Please read the Qt Code of Conduct -

Linux .ini resource file and font specification

  • Hello,

    This is in the context of the GPLv3+ RefPerSys "research" project (see these slides for motivation) on Linux only (either Debian/Sid/x86-64 on a AMD Ryzen Threadripper 2970WX desktop or Maegia 7/x86-64 on a i7 ACER Nitro 5 laptop). The audience of RefPerSys is only Linux developers interested in reflexive systems for artificial intelligence (not any kind of general user). The object model of RefPerSys -which can also be seen as an object oriented reflexive language implementation- claims to be more general than even the Qt meta object protocol (but inspired by it and by ObjVLisp). The source code is on and I am referring to commit d6b4b1bba06fc57d51e0b91.

    Qt version is Qt5.12.5 as packed in Debian/Sid. i.e the following Debian package

    libqt5widgets5:amd64 5.12.5+dfsg-10 amd64        Qt 5 widgets module

    and corresponding development packages, explained in our README. On the desktop the Xorg server is the package:

    xorg           1:7.7+20     amd64        X.Org X Window System

    More details about the context on our issue#30 and in this and following archived emails, in particular this one.

    So, we are running (in our file line 73) the following C++ code (compiled with GCC g++ 9.3 from Debian/Sid):

    QSettings* qst = RpsQApplication::qt_settings();
    constexpr const char*label_setting_name = "window_label_font";
    RPS_DEBUG_LOG(GUI, "RpsQWindow::RpsQWindow settings path: "
                  << qst->fileName().toStdString() << " "
                  << ((qst->contains(QString(label_setting_name)))?"has":"without")
                  << " "
                  << label_setting_name);
    QFont label_font = qst->value(label_setting_name).value<QFont>();
    int label_fontsize = label_font.pointSize();
    int label_minheight = (label_fontsize)>2?((4*label_fontsize)/3+1):10;
    int label_maxheight = (label_fontsize)>2?(2*label_fontsize):24;
    if (label_maxheight <= label_minheight+2)
      label_maxheight = (9*label_minheight)/8+1;
    RPS_DEBUG_LOG(GUI, "RpsQWindow::RpsQWindow " << label_setting_name << ":=" << label_font.toString().toStdString()
                  << ", label_fontsize=" << label_fontsize
                  << ", label_minheight=" << label_minheight
                  << ", label_maxheight=" << label_maxheight);

    where RPS_ASSERT and RPS_DEBUG_LOG are our macros (defined in our file refpersys.hh ) and doing what their name suggests (debugging logs happens via some std::ostringstream)

    We have one QSettings-managed resource file, our .qt-refpersys.ini file starting with:

    # default RefPerSys Qt settings
    # see and
    # file refpersys/.qt-refpersys.ini
    ## the font for windows label
    window_label_font=Bitstream Vera Sans,12

    We don't understand what is the expected syntax for QFont-s settings (on Linux)

    At runtime, we do observe (even with strace) that our resource file .qt-refpersys.ini is loaded, and the debugging messages indeed show

    ** RefPerSys INFORM! void rps_run_application(int&, char**) running the GUI since no batch mode
    RPS DEBUG    GUI <rps-main:407158> 10:03:12.96 
    RpsQWindow::RpsQWindow settings path: /home/basile/refpersys/.qt-refpersys.ini has window_label_font
    RPS DEBUG 0000 ~ 2020-May-05@10:03:1588665792.96 MEST *^*^*
    RPS DEBUG    GUI <rps-main:407158> 10:03:12.96 
    RpsQWindow::RpsQWindow window_label_font:=Sans,9,-1,5,50,0,0,0,0,0, label_fontsize=9, label_minheight=13, label_maxheight=18

    But why is the window_label_font a Sans font, given that we specified a Bitstream Vera Sans,12 and why is its size 9, but we want 12 points?

    Visually, the displayed font at runtime is not what we want. See attached images in our issue#26

    What am I doing wrong?


    PS. I don't care at all about portability to non-Linux Qt5 systems.

    Basile Starynkevitch
    near Paris, France

  • Lifetime Qt Champion

    You want to read the font name as QString, not as QFont since you store it as a string in your ini file.

  • @Christian-Ehrlicher
    but how should I convert that string to a loaded QFont? And how should I check that the font does exist on the running system?

    BTW, the .qt-refpersys.ini file is handwritten using emacs; I would prefer to avoid writing it programmatically.

  • Lifetime Qt Champion

    When you don't want to let save it by Qt you have to read the font attributes one by one from your ini file and then construct it with the QFont ctor